本文整理汇总了C#中ISessionImplementor.GuessEntityName方法的典型用法代码示例。如果您正苦于以下问题:C# ISessionImplementor.GuessEntityName方法的具体用法?C# ISessionImplementor.GuessEntityName怎么用?C# ISessionImplementor.GuessEntityName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISessionImplementor
的用法示例。
在下文中一共展示了ISessionImplementor.GuessEntityName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
}
示例2: addCollectionChangeWorkUnitToAuditProcess
private void addCollectionChangeWorkUnitToAuditProcess(ISessionImplementor session, AuditProcess auditProcess, object value)
{
// relDesc.getToEntityName() doesn't always return the entity name of the value - in case
// of subclasses, this will be root class, no the actual class. So it can't be used here.
string toEntityName;
object id;
var newValueAsProxy = value as INHibernateProxy;
if (newValueAsProxy != null)
{
toEntityName = session.BestGuessEntityName(value);
id = newValueAsProxy.HibernateLazyInitializer.Identifier;
// We've got to initialize the object from the proxy to later read its state.
value = Toolz.GetTargetFromProxy((ISession) session, newValueAsProxy);
}
else
{
toEntityName = session.GuessEntityName(value);
var idMapper = VerCfg.EntCfg[toEntityName].IdMapper;
id = idMapper.MapToIdFromEntity(value);
}
auditProcess.AddWorkUnit(new CollectionChangeWorkUnit(session, toEntityName, VerCfg, id, value));
}
示例3: GenerateBidirectionalCollectionChangeWorkUnits
private void GenerateBidirectionalCollectionChangeWorkUnits(AuditSync verSync, IEntityPersister entityPersister,
String entityName, Object[] newState, Object[] oldState,
ISessionImplementor session) {
// Checking if this is enabled in configuration ...
if (!verCfg.GlobalCfg.isGenerateRevisionsForCollections()) {
return;
}
// Checks every property of the entity, if it is an "owned" to-one relation to another entity.
// If the value of that property changed, and the relation is bi-directional, a new revision
// for the related entity is generated.
String[] propertyNames = entityPersister.PropertyNames;
for (int i=0; i<propertyNames.GetLength(0); i++) {
String propertyName = propertyNames[i];
RelationDescription relDesc = verCfg.EntCfg.GetRelationDescription(entityName, propertyName);
if (relDesc != null && relDesc.Bidirectional && relDesc.RelationType == RelationType.TO_ONE &&
relDesc.Insertable) {
// Checking for changes
Object oldValue = oldState == null ? null : oldState[i];
Object newValue = newState == null ? null : newState[i];
if (!Toolz.EntitiesEqual(session, oldValue, newValue)) {
// We have to generate changes both in the old collection (size decreses) and new collection
// (size increases).
//<TODO Simon: doua if-uri cu cod duplicat, refact.
if (newValue != null) {
// relDesc.getToEntityName() doesn't always return the entity name of the value - in case
// of subclasses, this will be root class, no the actual class. So it can't be used here.
String toEntityName;
// Java: Serializable id
object id;
if (newValue is INHibernateProxy) {
INHibernateProxy hibernateProxy = (INHibernateProxy) newValue;
toEntityName = session.BestGuessEntityName(newValue);
id = hibernateProxy.HibernateLazyInitializer.Identifier;
// We've got to initialize the object from the proxy to later read its state.
newValue = NHibernate.Envers.Tools.Toolz.GetTargetFromProxy(session.Factory, hibernateProxy);
} else {
toEntityName = session.GuessEntityName(newValue);
IIdMapper idMapper = verCfg.EntCfg[toEntityName].GetIdMapper();
id = idMapper.MapToIdFromEntity(newValue);
}
verSync.AddWorkUnit(new CollectionChangeWorkUnit(session, toEntityName, verCfg, id, newValue));
}
if (oldValue != null) {
String toEntityName;
object id;
if(oldValue is INHibernateProxy) {
INHibernateProxy hibernateProxy = (INHibernateProxy) oldValue;
toEntityName = session.BestGuessEntityName(oldValue);
id = hibernateProxy.HibernateLazyInitializer.Identifier;
// We've got to initialize the object as we'll read it's state anyway.
oldValue = Toolz.GetTargetFromProxy(session.Factory, hibernateProxy);
} else {
toEntityName = session.GuessEntityName(oldValue);
IIdMapper idMapper = verCfg.EntCfg[toEntityName].GetIdMapper();
id = idMapper.MapToIdFromEntity(oldValue);
}
verSync.AddWorkUnit(new CollectionChangeWorkUnit(session, toEntityName, verCfg, id, oldValue));
}
}
}
}
}