本文整理汇总了C#中IEntityPersister.GetIdentifier方法的典型用法代码示例。如果您正苦于以下问题:C# IEntityPersister.GetIdentifier方法的具体用法?C# IEntityPersister.GetIdentifier怎么用?C# IEntityPersister.GetIdentifier使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEntityPersister
的用法示例。
在下文中一共展示了IEntityPersister.GetIdentifier方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckId
/// <summary>
/// make sure user didn't mangle the id
/// </summary>
/// <param name="obj"></param>
/// <param name="persister"></param>
/// <param name="id"></param>
/// <param name="entityMode"></param>
public virtual void CheckId(object obj, IEntityPersister persister, object id, EntityMode entityMode)
{
if (id != null && id is DelayedPostInsertIdentifier)
{
// this is a situation where the entity id is assigned by a post-insert generator
// and was saved outside the transaction forcing it to be delayed
return;
}
if (persister.CanExtractIdOutOfEntity)
{
object oid = persister.GetIdentifier(obj, entityMode);
if (id == null)
{
throw new AssertionFailure("null id in " + persister.EntityName + " entry (don't flush the Session after an exception occurs)");
}
if (!persister.IdentifierType.IsEqual(id, oid, EntityMode.Poco))
{
throw new HibernateException("identifier of an instance of " + persister.EntityName + " was altered from " + id + " to " + oid);
}
}
}
示例2: GetIdentifier
/// <summary>
/// Get the identifier value of an instance or proxy.
/// <p/>
/// Intended only for loggin purposes!!!
/// </summary>
/// <param name="obj">The object from which to extract the identifier.</param>
/// <param name="persister">The entity persister </param>
/// <param name="entityMode">The entity mode </param>
/// <returns> The extracted identifier. </returns>
private static object GetIdentifier(object obj, IEntityPersister persister, EntityMode entityMode)
{
if (obj.IsProxy())
{
INHibernateProxy proxy = obj as INHibernateProxy;
ILazyInitializer li = proxy.HibernateLazyInitializer;
return li.Identifier;
}
else
{
return persister.GetIdentifier(obj, entityMode);
}
}
示例3: ExistsInDatabase
private static bool ExistsInDatabase(object entity, IEventSource source, IEntityPersister persister)
{
EntityEntry entry = source.PersistenceContext.GetEntry(entity);
if (entry == null)
{
object id = persister.GetIdentifier(entity, source.EntityMode);
if (id != null)
{
EntityKey key = new EntityKey(id, persister, source.EntityMode);
object managedEntity = source.PersistenceContext.GetEntity(key);
entry = source.PersistenceContext.GetEntry(managedEntity);
}
}
if (entry == null)
{
// perhaps this should be an exception since it is only ever used
// in the above method?
return false;
}
else
{
return entry.ExistsInDatabase;
}
}
示例4: GetUpdateId
/// <summary> Determine the id to use for updating. </summary>
/// <param name="entity">The entity. </param>
/// <param name="persister">The entity persister </param>
/// <param name="requestedId">The requested identifier </param>
/// <param name="entityMode">The entity mode. </param>
/// <returns> The id. </returns>
protected virtual object GetUpdateId(object entity, IEntityPersister persister, object requestedId, EntityMode entityMode)
{
// use the id assigned to the instance
object id = persister.GetIdentifier(entity, entityMode);
if (id == null)
{
// assume this is a newly instantiated transient object
// which should be saved rather than updated
throw new TransientObjectException("The given object has a null identifier: " + persister.EntityName);
}
else
{
return id;
}
}
示例5: GetIdentifier
public static object GetIdentifier(object obj, IEntityPersister persister)
{
if (obj is INHibernateProxy)
{
INHibernateProxy proxy = (INHibernateProxy) obj;
LazyInitializer li = GetLazyInitializer(proxy);
return li.Identifier;
}
else
{
return persister.GetIdentifier(obj);
}
}