本文整理汇总了C#中IEntityPersister.CreateProxy方法的典型用法代码示例。如果您正苦于以下问题:C# IEntityPersister.CreateProxy方法的具体用法?C# IEntityPersister.CreateProxy怎么用?C# IEntityPersister.CreateProxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IEntityPersister
的用法示例。
在下文中一共展示了IEntityPersister.CreateProxy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NarrowProxy
/// <summary>
/// If the existing proxy is insufficiently "narrow" (derived), instantiate a new proxy
/// and overwrite the registration of the old one. This breaks == and occurs only for
/// "class" proxies rather than "interface" proxies. Also init the proxy to point to
/// the given target implementation if necessary.
/// </summary>
/// <param name="proxy">The proxy instance to be narrowed. </param>
/// <param name="persister">The persister for the proxied entity. </param>
/// <param name="key">The internal cache key for the proxied entity. </param>
/// <param name="obj">(optional) the actual proxied entity instance. </param>
/// <returns> An appropriately narrowed instance. </returns>
public object NarrowProxy(INHibernateProxy proxy, IEntityPersister persister, EntityKey key, object obj)
{
bool alreadyNarrow = persister.GetConcreteProxyClass(session.EntityMode).IsAssignableFrom(proxy.GetType());
if (!alreadyNarrow)
{
if (ProxyWarnLog.IsWarnEnabled)
{
ProxyWarnLog.Warn("Narrowing proxy to " + persister.GetConcreteProxyClass(session.EntityMode) + " - this operation breaks ==");
}
if (obj != null)
{
proxiesByKey.Remove(key);
return obj; //return the proxied object
}
else
{
proxy = (INHibernateProxy)persister.CreateProxy(key.Identifier, session);
proxiesByKey[key] = proxy; //overwrite old proxy
return proxy;
}
}
else
{
if (obj != null)
{
proxy.HibernateLazyInitializer.SetImplementation(obj);
}
return proxy;
}
}
示例2: 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;
}
}