本文整理汇总了C#中IPersistenceContext.AddProxy方法的典型用法代码示例。如果您正苦于以下问题:C# IPersistenceContext.AddProxy方法的具体用法?C# IPersistenceContext.AddProxy怎么用?C# IPersistenceContext.AddProxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPersistenceContext
的用法示例。
在下文中一共展示了IPersistenceContext.AddProxy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateProxyIfNecessary
/// <summary>
/// Given that there is no pre-existing proxy.
/// Check if the entity is already loaded. If it is, return the entity,
/// otherwise create and return a proxy.
/// </summary>
private object CreateProxyIfNecessary(LoadEvent @event, IEntityPersister persister, EntityKey keyToLoad, LoadType options, IPersistenceContext persistenceContext)
{
object existing = persistenceContext.GetEntity(keyToLoad);
if (existing != null)
{
// return existing object or initialized proxy (unless deleted)
log.Debug("entity found in session cache");
if (options.IsCheckDeleted)
{
EntityEntry entry = persistenceContext.GetEntry(existing);
Status status = entry.Status;
if (status == Status.Deleted || status == Status.Gone)
{
return null;
}
}
return existing;
}
else
{
log.Debug("creating new proxy for entity");
// return new uninitialized proxy
object proxy = persister.CreateProxy(@event.EntityId, @event.Session);
persistenceContext.BatchFetchQueue.AddBatchLoadableEntityKey(keyToLoad);
persistenceContext.AddProxy(keyToLoad, (INHibernateProxy)proxy);
((INHibernateProxy)proxy)
.HibernateLazyInitializer
.ReadOnly = @event.Session.DefaultReadOnly || !persister.IsMutable;
return proxy;
}
}