当前位置: 首页>>代码示例>>C#>>正文


C# ISessionImplementor.GetEntityPersister方法代码示例

本文整理汇总了C#中ISessionImplementor.GetEntityPersister方法的典型用法代码示例。如果您正苦于以下问题:C# ISessionImplementor.GetEntityPersister方法的具体用法?C# ISessionImplementor.GetEntityPersister怎么用?C# ISessionImplementor.GetEntityPersister使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ISessionImplementor的用法示例。


在下文中一共展示了ISessionImplementor.GetEntityPersister方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Generate

        /// <summary>
        /// Generates a new identifier by getting the value of the identifier
        /// for the <c>obj</c> parameter.
        /// </summary>
        /// <param name="session">The <see cref="ISessionImplementor"/> this id is being generated in.</param>
        /// <param name="obj">The entity for which the id is being generated.</param>
        /// <returns>The value that was assigned to the mapped <c>id</c>'s property.</returns>
        /// <exception cref="IdentifierGenerationException">
        /// Thrown when a <see cref="IPersistentCollection"/> is passed in as the <c>obj</c> or
        /// if the identifier of <c>obj</c> is null.
        /// </exception>
        public object Generate(ISessionImplementor session, object obj)
        {
            if (obj is IPersistentCollection)
            {
                throw new IdentifierGenerationException("Illegal use of assigned id generation for a toplevel collection");
            }

            object id = session.GetEntityPersister(obj).GetIdentifier(obj, session.EntityMode);
            if (id == null)
            {
                throw new IdentifierGenerationException("ids for this class must be manually assigned before calling save(): "
                                                                                                + obj.GetType().FullName);
            }
            return id;
        }
开发者ID:zibler,项目名称:zibler,代码行数:26,代码来源:Assigned.cs

示例2: Generate

        /// <summary>
        /// Generate a new identifier.
        /// </summary>
        /// <param name="session">The <see cref="ISessionImplementor"/> this id is being generated in.</param>
        /// <param name="obj">The entity for which the id is being generated.</param>
        /// <returns>The new identifier.</returns>
        public object Generate(ISessionImplementor session, object obj)
        {
            if (obj != null)
            {
                // If the object we're generating a GUID for already has a GUID,
                // then we won't change it. This is to facilitate exporting/importing between different systems.
                var perister = session.GetEntityPersister(null, obj);
                var property = obj.GetType().GetProperty(perister.IdentifierPropertyName);
                var id = property.GetValue(obj, null);

                if (id != null && id is Guid)
                {
                    var guid = (Guid)id;
                    if (!guid.Equals(Guid.Empty)) return guid;
                }
            }

            return GenerateComb();
        }
开发者ID:DavidMoore,项目名称:Foundation,代码行数:25,代码来源:CustomGuidCombGenerator.cs

示例3: GetEntityIdentifierIfNotUnsaved

        /// <summary> 
        /// Return the identifier of the persistent or transient object, or throw
        /// an exception if the instance is "unsaved"
        /// </summary>
        /// <remarks>
        /// Used by OneToOneType and ManyToOneType to determine what id value should 
        /// be used for an object that may or may not be associated with the session. 
        /// This does a "best guess" using any/all info available to use (not just the 
        /// EntityEntry).
        /// </remarks>
        public static object GetEntityIdentifierIfNotUnsaved(string entityName, object entity, ISessionImplementor session)
        {
            if (entity == null)
            {
                return null;
            }
            else
            {
                object id = session.GetContextEntityIdentifier(entity);
                if (id == null)
                {
                    // context-entity-identifier returns null explicitly if the entity
                    // is not associated with the persistence context; so make some deeper checks...

                    /***********************************************/
                    // NH-479 (very dirty patch)
                    if (entity.GetType().IsPrimitive)
                        return entity;
                    /**********************************************/

                    if (IsTransient(entityName, entity, false, session))
                    {
                        /***********************************************/
                        // TODO NH verify the behavior of NH607 test
                        // these lines are only to pass test NH607 during PersistenceContext porting
                        // i'm not secure that NH607 is a test for a right behavior
                        EntityEntry entry = session.PersistenceContext.GetEntry(entity);
                        if (entry != null)
                            return entry.Id;
                        // the check was put here to have les possible impact
                        /**********************************************/

                        throw new TransientObjectException(
                            "object references an unsaved transient instance - save the transient instance before flushing: "
                            + (entityName ?? session.GuessEntityName(entity)));
                    }
                    id = session.GetEntityPersister(entityName, entity).GetIdentifier(entity, session.EntityMode);
                }
                return id;
            }
        }
开发者ID:zibler,项目名称:zibler,代码行数:51,代码来源:ForeignKeys.cs

示例4: GetOptionalObjectKey

		// Not ported: sequentialLoad, loadSequentialRowsForward, loadSequentialRowsReverse

		internal static EntityKey GetOptionalObjectKey(QueryParameters queryParameters, ISessionImplementor session)
		{
			object optionalObject = queryParameters.OptionalObject;
			object optionalId = queryParameters.OptionalId;
			string optionalEntityName = queryParameters.OptionalEntityName;

			if (optionalObject != null && !string.IsNullOrEmpty(optionalEntityName))
			{
				return new EntityKey(optionalId, session.GetEntityPersister(optionalEntityName, optionalObject), session.EntityMode);
			}
			else
			{
				return null;
			}
		}
开发者ID:remcoros,项目名称:nhibernate,代码行数:17,代码来源:Loader.cs

示例5: IsTransient

		/// <summary> 
		/// Is this instance, which we know is not persistent, actually transient? 
		/// If <tt>assumed</tt> is non-null, don't hit the database to make the 
		/// determination, instead assume that value; the client code must be 
		/// prepared to "recover" in the case that this assumed result is incorrect.
		/// </summary>
		/// <remarks>
		/// If <paramref name="assumed"/> is non-null, don't hit the database to make the 
		/// determination, instead assume that value; the client code must be 
		/// prepared to "recover" in the case that this assumed result is incorrect.
		/// </remarks>
		public static bool IsTransient(string entityName, object entity, bool? assumed, ISessionImplementor session)
		{
			if (entity == Intercept.LazyPropertyInitializer.UnfetchedProperty)
			{
				// an unfetched association can only point to
				// an entity that already exists in the db
				return false;
			}

			// let the interceptor inspect the instance to decide
			bool? isUnsaved = session.Interceptor.IsTransient(entity);
			if (isUnsaved.HasValue)
				return isUnsaved.Value;

			// let the persister inspect the instance to decide
			IEntityPersister persister = session.GetEntityPersister(entityName, entity);
			isUnsaved = persister.IsTransient(entity, session);
			if (isUnsaved.HasValue)
				return isUnsaved.Value;

			// we use the assumed value, if there is one, to avoid hitting
			// the database
			if (assumed.HasValue)
				return assumed.Value;

			if (persister.IdentifierGenerator is Assigned)
			{
				// When using assigned identifiers we cannot tell if an entity
				// is transient or detached without querying the database.
				// This could potentially cause Select N+1 in cascaded saves, so warn the user.
				log.Warn("Unable to determine if " + entity.ToString()
					+ " with assigned identifier " + persister.GetIdentifier(entity, session.EntityMode)
					+ " is transient or detached; querying the database."
					+ " Use explicit Save() or Update() in session to prevent this.");
			}

			// hit the database, after checking the session cache for a snapshot
			System.Object[] snapshot =
				session.PersistenceContext.GetDatabaseSnapshot(persister.GetIdentifier(entity, session.EntityMode), persister);
			return snapshot == null;
		}
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:52,代码来源:ForeignKeys.cs

示例6: Hydrate

		public override object Hydrate(IDataReader rs, string[] names, ISessionImplementor session, object owner)
		{
			IType type = GetIdentifierOrUniqueKeyType(session.Factory);
			object identifier = session.GetContextEntityIdentifier(owner);

			//This ugly mess is only used when mapping one-to-one entities with component ID types
			EmbeddedComponentType componentType = type as EmbeddedComponentType;
			if (componentType != null)
			{
				EmbeddedComponentType ownerIdType = session.GetEntityPersister(null, owner).IdentifierType as EmbeddedComponentType;
				if (ownerIdType != null)
				{
					object[] values = ownerIdType.GetPropertyValues(identifier, session);
					object id = componentType.ResolveIdentifier(values, session, null);
					IEntityPersister persister = session.Factory.GetEntityPersister(type.ReturnedClass.FullName);
					var key = new EntityKey(id, persister, session.EntityMode);
					return session.PersistenceContext.GetEntity(key);
				}
			}
			return identifier;
		}
开发者ID:hazzik,项目名称:nh-contrib-everything,代码行数:21,代码来源:OneToOneType.cs

示例7: GetOptionalObjectKey

		// Not ported: sequentialLoad, loadSequentialRowsForward, loadSequentialRowsReverse

		internal static EntityKey GetOptionalObjectKey(QueryParameters queryParameters, ISessionImplementor session)
		{
			object optionalObject = queryParameters.OptionalObject;
			object optionalId = queryParameters.OptionalId;
			System.Type optionalEntityClass = queryParameters.OptionalEntityClass;

			if (optionalObject != null && optionalEntityClass != null)
			{
				return new EntityKey(
					optionalId,
					session.GetEntityPersister(optionalObject)
					// TODO H3: session.GetEntityPersister( optionalEntityName, optionalObject )
					// TODO H3: session.getEntityMode()
					);
			}
			else
			{
				return null;
			}
		}
开发者ID:Novthirteen,项目名称:sconit_timesseiko,代码行数:22,代码来源:Loader.cs

示例8: IsTransient

        /// <summary> 
        /// Is this instance, which we know is not persistent, actually transient? 
        /// If <tt>assumed</tt> is non-null, don't hit the database to make the 
        /// determination, instead assume that value; the client code must be 
        /// prepared to "recover" in the case that this assumed result is incorrect.
        /// </summary>
        /// <remarks>
        /// If <paramref name="assumed"/> is non-null, don't hit the database to make the 
        /// determination, instead assume that value; the client code must be 
        /// prepared to "recover" in the case that this assumed result is incorrect.
        /// </remarks>
        public static bool IsTransient(string entityName, object entity, bool? assumed, ISessionImplementor session)
        {
            if (entity == Intercept.LazyPropertyInitializer.UnfetchedProperty)
            {
                // an unfetched association can only point to
                // an entity that already exists in the db
                return false;
            }

            // let the interceptor inspect the instance to decide
            bool? isUnsaved = session.Interceptor.IsTransient(entity);
            if (isUnsaved.HasValue)
                return isUnsaved.Value;

            // let the persister inspect the instance to decide
            IEntityPersister persister = session.GetEntityPersister(entity);
            isUnsaved = persister.IsTransient(entity, session);
            if (isUnsaved.HasValue)
                return isUnsaved.Value;

            // we use the assumed value, if there is one, to avoid hitting
            // the database
            if (assumed.HasValue)
                return assumed.Value;

            // hit the database, after checking the session cache for a snapshot
            System.Object[] snapshot =
                session.PersistenceContext.GetDatabaseSnapshot(persister.GetIdentifier(entity, session.EntityMode), persister);
            return snapshot == null;
        }
开发者ID:zibler,项目名称:zibler,代码行数:41,代码来源:ForeignKeys.cs


注:本文中的ISessionImplementor.GetEntityPersister方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。