本文整理汇总了C#中IPropertyMap.MustGetReferencedClassMap方法的典型用法代码示例。如果您正苦于以下问题:C# IPropertyMap.MustGetReferencedClassMap方法的具体用法?C# IPropertyMap.MustGetReferencedClassMap怎么用?C# IPropertyMap.MustGetReferencedClassMap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPropertyMap
的用法示例。
在下文中一共展示了IPropertyMap.MustGetReferencedClassMap方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ManageReferenceValue
//if value is a list, values in list come in the same order as columns are returned from propertymap.refClassMap.GetIdentityCols! garantueed order !
//type column value must have been extracted from list in advance and should be passed to discriminator param
public virtual object ManageReferenceValue(object obj, IPropertyMap propertyMap, object value, object discriminator)
{
IClassMap refClassMap;
IPropertyMap mapToId;
bool isIdentity = false;
if (!(propertyMap.ReferenceType == ReferenceType.None))
{
if (value != null)
{
string identity = "";
refClassMap = propertyMap.MustGetReferencedClassMap();
if (discriminator != null)
{
try
{
discriminator = discriminator.ToString() ;
}
catch { discriminator = ""; }
refClassMap = refClassMap.GetSubClassWithTypeValue((string) discriminator);
if (refClassMap == null)
throw new NPersistException("Could not find class map with type value '" + (string) discriminator + "'");
}
mapToId = refClassMap.MustGetPropertyMapForColumnMap(propertyMap.GetColumnMap().MustGetPrimaryKeyColumnMap());
if (mapToId.IsIdentity)
{
isIdentity = true;
IList valueAsList = value as IList;
if (valueAsList == null)
identity = Convert.ToString(value);
else
{
string separator = refClassMap.GetIdentitySeparator();
if (separator == "")
{
separator = "|";
}
StringBuilder identityBuilder = new StringBuilder() ;
foreach (object valueItem in valueAsList)
identityBuilder.Append(Convert.ToString(valueItem) + separator) ;
identityBuilder.Length -= separator.Length;
identity = identityBuilder.ToString();
}
}
if (isIdentity)
{
return this.Context.GetObjectById(identity, this.Context.AssemblyManager.MustGetTypeFromClassMap(refClassMap), true);
}
else
return this.Context.GetObjectByKey(mapToId.Name, Convert.ToString(value), obj.GetType().GetProperty(propertyMap.Name).PropertyType);
}
}
return value;
}
示例2: FromPropertyReference
private MarshalReferenceValue FromPropertyReference(object sourceObject, object value, IPropertyMap propertyMap)
{
MarshalReferenceValue mrv = new MarshalReferenceValue() ;
if (value != null)
{
foreach (IPropertyMap idPropertyMap in propertyMap.MustGetReferencedClassMap().GetIdentityPropertyMaps())
{
if (idPropertyMap.ReferenceType == ReferenceType.None)
{
mrv.ReferenceProperties.Add(FromProperty(value, idPropertyMap)) ;
}
else
{
mrv.ReferenceReferences.Add(FromReference(value, idPropertyMap)) ;
}
}
}
return mrv;
}
示例3: FromReference
private MarshalReference FromReference(object sourceObject, IPropertyMap propertyMap)
{
MarshalReference mr = new MarshalReference();
mr.Name = propertyMap.Name;
object value = Context.ObjectManager.GetPropertyValue(sourceObject, propertyMap.Name);
if (value != null)
{
IClassMap classMap = Context.DomainMap.MustGetClassMap(value.GetType());
mr.Type = classMap.GetName() ;
mr.IsNull = false;
}
else
{
IClassMap refClassMap = propertyMap.MustGetReferencedClassMap() ;
if (refClassMap != null)
mr.Type = refClassMap.GetName() ;
mr.IsNull = true;
}
mr.Value = FromPropertyReference(sourceObject, value, propertyMap);
if (Context.ObjectManager.HasOriginalValues(sourceObject, propertyMap.Name))
{
object orgValue = Context.ObjectManager.GetOriginalPropertyValue(sourceObject, propertyMap.Name);
mr.OriginalValue = FromPropertyReference(sourceObject, orgValue, propertyMap);
mr.HasOriginal = true;
if (orgValue != null)
{
IClassMap orgClassMap = Context.DomainMap.MustGetClassMap(orgValue.GetType());
mr.OriginalType = orgClassMap.GetName() ;
mr.WasNull = false;
}
else
{
IClassMap refClassMap = propertyMap.MustGetReferencedClassMap() ;
if (refClassMap != null)
mr.OriginalType = refClassMap.GetName() ;
mr.WasNull = true;
}
}
else
{
//mr.OriginalValue = FromPropertyReference(sourceObject, null, propertyMap);
mr.HasOriginal = false;
}
return mr;
}
示例4: LoadCollectionProperty
protected virtual void LoadCollectionProperty(object obj, IPropertyMap propertyMap)
{
IList parameters;
object value;
Type itemType = null;
IList list;
IInterceptableList mList;
bool stackMute = false;
IContext ctx = m_SqlEngineManager.Context;
if (!(propertyMap.ReferenceType == ReferenceType.None))
{
itemType = m_SqlEngineManager.Context.AssemblyManager.MustGetTypeFromClassMap(propertyMap.MustGetReferencedClassMap());
LoadReferenceCollectionProperty(obj, propertyMap, itemType);
return;
}
parameters = new ArrayList() ;
IList propList = m_SqlEngineManager.Context.ListManager.CreateList(obj, propertyMap);
IObjectManager om = ctx.ObjectManager;
IListManager lm = ctx.ListManager;
IPersistenceManager pm = ctx.PersistenceManager;
string sql = GetSelectCollectionPropertyStatement(obj, propertyMap.Name, parameters);
IDataSource ds = ctx.DataSourceManager.GetDataSource(obj);
object[,] result = (object[,]) ctx.SqlExecutor.ExecuteArray(sql, ds, parameters);
if (Util.IsArray(result))
{
mList = propList as IInterceptableList;
if (mList != null)
{
stackMute = mList.MuteNotify;
mList.MuteNotify = true;
}
for (int row = 0; row <= result.GetUpperBound(1); row++)
{
value = result[0, row];
if (!(propertyMap.ReferenceType == ReferenceType.None))
{
if (Convert.IsDBNull(value))
{
value = null;
}
else
{
value = pm.ManageReferenceValue(obj, propertyMap.Name, value);
}
}
propList.Add(value);
}
if (mList != null)
mList.MuteNotify = stackMute ;
om.SetPropertyValue(obj, propertyMap.Name, propList);
list = lm.CloneList(obj, propertyMap, propList);
om.SetOriginalPropertyValue(obj, propertyMap.Name, list);
}
else
{
throw new ObjectNotFoundException("Object not found!"); // do not localize
}
}
示例5: WrapValue
protected virtual string WrapValue(object obj, IPropertyMap propertyMap, object value, IColumnMap columnMap, ref string compareOp, bool noNullStatusCheck)
{
string dateFormat;
DbType dataType = columnMap.DataType;
IPropertyMap idPropertyMap;
IObjectManager om = m_SqlEngineManager.Context.ObjectManager;
IClassMap refClassMap;
IColumnMap forColMap;
IClassMap realRefClassMap;
compareOp = "=";
if (Convert.IsDBNull(value) || value == null)
{
compareOp = "Is";
return "NULL";
}
if (!(noNullStatusCheck))
{
if (om.GetNullValueStatus(obj, propertyMap.Name))
{
compareOp = "Is";
return "NULL";
}
}
if (propertyMap != null)
{
if (!(propertyMap.ReferenceType == ReferenceType.None))
{
if (value == null)
{
compareOp = "Is";
return "NULL";
}
else
{
if (om.GetObjectStatus(value) == ObjectStatus.UpForCreation)
{
compareOp = "Is";
return "NULL";
}
else
{
refClassMap = propertyMap.MustGetReferencedClassMap();
forColMap = columnMap.MustGetPrimaryKeyColumnMap();
dataType = forColMap.DataType;
IColumnMap typeColumnMap = refClassMap.GetTypeColumnMap();
if (typeColumnMap != null && typeColumnMap == forColMap)
{
realRefClassMap = refClassMap.DomainMap.MustGetClassMap(value.GetType());
value = realRefClassMap.TypeValue;
}
else
{
idPropertyMap = refClassMap.MustGetPropertyMapForColumnMap(forColMap);
value = om.GetPropertyValue(value, idPropertyMap.Name);
}
}
}
}
}
if (dataType == DbType.AnsiString || dataType == DbType.AnsiStringFixedLength || dataType == DbType.String || dataType == DbType.StringFixedLength)
{
if (columnMap.Precision == 0 || columnMap.Precision >= 4000)
{
compareOp = "LIKE";
}
return "'" + Convert.ToString(value).Replace("'", "''") + "'";
}
else if (dataType == DbType.Date || dataType == DbType.DateTime || dataType == DbType.Time)
{
dateFormat = columnMap.Format;
if (dateFormat == "")
{
dateFormat = "yyyy-MM-dd HH:mm:ss"; // do not localize
}
return DateDelimiter + Convert.ToDateTime(value).ToString(dateFormat) + DateDelimiter;
}
else if (dataType == DbType.Byte || dataType == DbType.Decimal || dataType == DbType.Double || dataType == DbType.Int16 || dataType == DbType.Int32 || dataType == DbType.Int64 || dataType == DbType.SByte || dataType == DbType.Single || dataType == DbType.UInt16 || dataType == DbType.UInt32 || dataType == DbType.UInt64 || dataType == DbType.VarNumeric)
{
return Convert.ToString(value).Replace(",", ".");
}
else if (dataType == DbType.Boolean)
{
return WrapBoolean(Convert.ToBoolean(value));
}
else if (dataType == DbType.Currency)
{
return Convert.ToString(value).Replace(",", ".");
}
else if (dataType == DbType.Binary)
{
return "";
}
else if (dataType == DbType.Guid)
{
return "'" + Convert.ToString(value).Replace("'", "''") + "'";
}
else if (dataType == DbType.Object)
{
return "";
//.........这里部分代码省略.........
示例6: GetSelectSingleReferencePropertyStatement
//Mats : Fixed non-primary ref prop bug by improving One-One backref identification
protected virtual string GetSelectSingleReferencePropertyStatement(object obj, IPropertyMap propertyMap, IList idColumns, IList typeColumns, Hashtable hashPropertyColumnMap, IList parameters)
{
IColumnMap columnMap;
IClassMap classMap;
IPropertyMap refPropertyMap;
ITableMap tableMap;
IPropertyMap myPropertyMap;
string colName;
IColumnMap theColumnMap;
IColumnMap forColumnMap;
ITableMap forTableMap;
IColumnMap addColumnMap;
IColumnMap addForColumnMap;
ITableMap addForTableMap;
IColumnMap typeColumnMap;
IDomainMap domainMap;
bool isBackRef = false;
string paramName = "";
classMap = propertyMap.MustGetReferencedClassMap();
if (propertyMap.ReferenceType == ReferenceType.OneToOne)
{
columnMap = propertyMap.GetColumnMap();
if (columnMap != null)
if (columnMap.TableMap == propertyMap.MustGetReferencedClassMap().MustGetTableMap())
if (columnMap.IsPrimaryKey)
isBackRef = true;
columnMap = null;
}
SqlSelectStatement select;
SqlTableAlias table;
SqlColumnAlias theColumn;
SqlTableAlias forTable;
SqlColumnAlias forColumn;
if (isBackRef)
{
tableMap = propertyMap.ClassMap.MustGetTableMap();
select = new SqlSelectStatement(tableMap.SourceMap) ;
table = select.GetSqlTableAlias(tableMap);
//select.SqlSelectClause.AddSqlAliasSelectListItem(column);
//select.SqlFromClause.AddSqlAliasTableSource(table);
theColumnMap = propertyMap.GetIdColumnMap();
//theColumn = table.GetSqlColumnAlias(theColumnMap);
forTableMap = theColumnMap.TableMap;
forColumnMap = theColumnMap;
theColumnMap = forColumnMap.MustGetPrimaryKeyColumnMap();
if (forTableMap == null)
throw new MappingException("TableMap '" + theColumnMap.PrimaryKeyTable + "' Not Found!"); // do not localize
if (forColumnMap == null)
throw new MappingException("ColumnMap '" + theColumnMap.PrimaryKeyColumn + "' Not Found!"); // do not localize
forTable = select.GetSqlTableAlias(forTableMap);
forColumn = forTable.GetSqlColumnAlias(forColumnMap);
}
else
{
tableMap = propertyMap.MustGetTableMap();
select = new SqlSelectStatement(tableMap.SourceMap) ;
table = select.GetSqlTableAlias(tableMap);
theColumnMap = propertyMap.GetColumnMap();
//theColumn = table.GetSqlColumnAlias(theColumnMap);
forTableMap = theColumnMap.MustGetPrimaryKeyTableMap();
forColumnMap = theColumnMap.MustGetPrimaryKeyColumnMap();
if (forTableMap == null)
throw new MappingException("TableMap '" + theColumnMap.PrimaryKeyTable + "' Not Found!"); // do not localize
if (forColumnMap == null)
throw new MappingException("ColumnMap '" + theColumnMap.PrimaryKeyColumn + "' Not Found!"); // do not localize
forTable = select.GetSqlTableAlias(forTableMap);
forColumn = forTable.GetSqlColumnAlias(forColumnMap);
}
IObjectManager om;
foreach (IPropertyMap iRefPropertyMap in classMap.GetPrimaryPropertyMaps())
{
refPropertyMap = iRefPropertyMap;
if (!(propertyMap.LazyLoad))
{
if (!((refPropertyMap.IsCollection || (refPropertyMap.ReferenceType != ReferenceType.None && !(refPropertyMap.IsIdentity)))))
{
IColumnMap refColumnMap = refPropertyMap.GetColumnMap();
SqlColumnAlias refColumn = forTable.GetSqlColumnAlias(refColumnMap);
colName = refColumnMap.Name;
if (refPropertyMap.IsIdentity)
idColumns.Add(colName);
if (!(refPropertyMap.LazyLoad))
{
//.........这里部分代码省略.........
示例7: GetSelectManyManyPropertyStatement
protected virtual string GetSelectManyManyPropertyStatement(object obj, IPropertyMap propertyMap, IList idColumns, IList typeColumns, Hashtable hashPropertyColumnMap, IList parameters)
{
IColumnMap columnMap;
IClassMap classMap;
IPropertyMap refPropertyMap;
ITableMap tableMap;
ITableMap joinTableMap;
string colName;
IObjectManager om;
IColumnMap idColumnMap;
IPropertyMap myPropertyMap;
IColumnMap myColumnMap;
ITableMap myTableMap;
IColumnMap colColumnMap;
IColumnMap forColumnMap;
ITableMap forTableMap;
IColumnMap addColumnMap;
IColumnMap addIdColumnMap;
IColumnMap addMyColumnMap;
ITableMap addMyTableMap;
IColumnMap typeColumnMap;
IPropertyMap orderByMap;
string paramName = "";
classMap = propertyMap.MustGetReferencedClassMap();
tableMap = classMap.MustGetTableMap();
SqlSelectStatement select = new SqlSelectStatement(tableMap.SourceMap) ;
SqlTableAlias table = select.GetSqlTableAlias(tableMap);
joinTableMap = propertyMap.MustGetTableMap();
SqlTableAlias joinTable = select.GetSqlTableAlias(joinTableMap);
idColumnMap = propertyMap.GetIdColumnMap();
SqlColumnAlias idColumn = joinTable.GetSqlColumnAlias(idColumnMap);
myTableMap = idColumnMap.MustGetPrimaryKeyTableMap();
myColumnMap = idColumnMap.MustGetPrimaryKeyColumnMap();
if (myTableMap == null)
throw new MappingException("TableMap '" + idColumnMap.PrimaryKeyTable + "' Not Found!"); // do not localize
if (myColumnMap == null)
throw new MappingException("ColumnMap '" + idColumnMap.PrimaryKeyColumn + "' Not Found!"); // do not localize
SqlTableAlias myTable;
colColumnMap = propertyMap.GetColumnMap();
forTableMap = colColumnMap.MustGetPrimaryKeyTableMap();
forColumnMap = colColumnMap.MustGetPrimaryKeyColumnMap();
if (forTableMap == null)
throw new MappingException("TableMap '" + idColumnMap.PrimaryKeyTable + "' Not Found!"); // do not localize
if (forColumnMap == null)
throw new MappingException("ColumnMap '" + idColumnMap.PrimaryKeyColumn + "' Not Found!"); // do not localize
SqlTableAlias forTable = select.GetSqlTableAlias(forTableMap);
SqlColumnAlias forColumn = forTable.GetSqlColumnAlias(forColumnMap);
SqlColumnAlias colColumn = joinTable.GetSqlColumnAlias(colColumnMap);
orderByMap = propertyMap.GetOrderByPropertyMap();
foreach (IPropertyMap iRefPropertyMap in classMap.GetPrimaryPropertyMaps())
{
refPropertyMap = iRefPropertyMap;
if (!((refPropertyMap.IsCollection || (refPropertyMap.ReferenceType != ReferenceType.None && !(refPropertyMap.IsIdentity)))))
{
IColumnMap refColumnMap = refPropertyMap.GetColumnMap();
SqlColumnAlias refColumn = select.GetSqlColumnAlias(refColumnMap);
colName = refColumnMap.Name;
if (refPropertyMap.IsIdentity)
idColumns.Add(colName);
if (!(refPropertyMap.LazyLoad))
{
select.SqlSelectClause.AddSqlAliasSelectListItem(refColumn);
hashPropertyColumnMap[refPropertyMap.Name] = colName;
if (refPropertyMap == orderByMap)
select.SqlOrderByClause.AddSqlOrderByItem(refColumn);
}
}
}
typeColumnMap = classMap.GetTypeColumnMap();
if (typeColumnMap != null)
{
typeColumns.Add(typeColumnMap.Name);
SqlColumnAlias typeColumn = select.GetSqlColumnAlias(typeColumnMap);
select.SqlSelectClause.AddSqlAliasSelectListItem(typeColumn);
}
select.SqlFromClause.AddSqlAliasTableSource(table);
select.SqlFromClause.AddSqlAliasTableSource(joinTable);
//if (tableMap.SourceMap.Schema.ToLower(CultureInfo.InvariantCulture) == myTableMap.SourceMap.Schema.ToLower(CultureInfo.InvariantCulture) && tableMap.Name.ToLower(CultureInfo.InvariantCulture) == myTableMap.Name.ToLower(CultureInfo.InvariantCulture))
if (tableMap == myTableMap)
myTable = select.GetSqlTableAlias(myTableMap, "NPersistSelfRefTable");
else
myTable = select.GetSqlTableAlias(myTableMap);
SqlColumnAlias myColumn = myTable.GetSqlColumnAlias(myColumnMap);
select.SqlFromClause.AddSqlAliasTableSource(myTable);
SqlSearchCondition search = select.SqlWhereClause.GetNextSqlSearchCondition();
search.GetSqlComparePredicate(forColumn, SqlCompareOperatorType.Equals, colColumn);
//.........这里部分代码省略.........
示例8: AddSqlParameter
protected virtual SqlParameter AddSqlParameter(SqlStatement sqlStatement, IList parameters, string paramName, object obj, IPropertyMap propertyMap, object value, IColumnMap columnMap, bool noNullStatusCheck)
{
DbType dataType = columnMap.DataType;
IPropertyMap idPropertyMap;
IObjectManager om = m_SqlEngineManager.Context.ObjectManager;
IClassMap refClassMap;
IColumnMap forColMap;
IClassMap realRefClassMap;
IQueryParameter param = new QueryParameter(paramName, columnMap.DataType) ;
parameters.Add(param);
SqlParameter sqlParameter = sqlStatement.AddSqlParameter(paramName, dataType);
if (Convert.IsDBNull(value) || value == null)
{
param.Value = DBNull.Value;
}
if (!(noNullStatusCheck))
{
if (om.GetNullValueStatus(obj, propertyMap.Name))
{
param.Value = DBNull.Value;
sqlParameter.Value = DBNull.Value;
return sqlParameter;
}
}
if (propertyMap != null)
{
if (!(propertyMap.ReferenceType == ReferenceType.None))
{
if (value == null)
{
param.Value = DBNull.Value;
sqlParameter.Value = DBNull.Value;
return sqlParameter;
}
else
{
if (om.GetObjectStatus(value) == ObjectStatus.UpForCreation)
{
param.Value = DBNull.Value;
sqlParameter.Value = DBNull.Value;
return sqlParameter;
}
else
{
refClassMap = propertyMap.MustGetReferencedClassMap();
forColMap = columnMap.MustGetPrimaryKeyColumnMap();
dataType = forColMap.DataType;
if (refClassMap.GetTypeColumnMap() != null && refClassMap.GetTypeColumnMap() == forColMap)
{
realRefClassMap = refClassMap.DomainMap.MustGetClassMap(value.GetType());
value = realRefClassMap.TypeValue;
}
else
{
idPropertyMap = refClassMap.MustGetPropertyMapForColumnMap(forColMap);
value = om.GetPropertyValue(value, idPropertyMap.Name);
}
}
}
}
}
param.Value = value;
sqlParameter.Value = value;
return sqlParameter;
}
示例9: AddParameter
protected virtual void AddParameter(IList parameters, string paramName, object obj, IPropertyMap propertyMap, object value, IColumnMap columnMap, ref string compareOp, bool noNullStatusCheck)
{
DbType dataType = columnMap.DataType;
IPropertyMap idPropertyMap;
IObjectManager om = m_SqlEngineManager.Context.ObjectManager;
IClassMap refClassMap;
IColumnMap forColMap;
IClassMap realRefClassMap;
IQueryParameter param = new QueryParameter(paramName, columnMap.DataType) ;
parameters.Add(param);
compareOp = "=";
if (Convert.IsDBNull(value) || value == null)
{
//compareOp = "Is";
param.Value = DBNull.Value;
return;
}
if (!(noNullStatusCheck))
{
if (om.GetNullValueStatus(obj, propertyMap.Name))
{
//compareOp = "Is";
param.Value = DBNull.Value;
return;
}
}
if (propertyMap != null)
{
if (!(propertyMap.ReferenceType == ReferenceType.None))
{
if (value == null)
{
//compareOp = "Is";
param.Value = DBNull.Value;
return;
}
else
{
if (om.GetObjectStatus(value) == ObjectStatus.UpForCreation)
{
//compareOp = "Is";
param.Value = DBNull.Value;
return;
}
else
{
refClassMap = propertyMap.MustGetReferencedClassMap();
forColMap = columnMap.MustGetPrimaryKeyColumnMap();
dataType = forColMap.DataType;
if (refClassMap.GetTypeColumnMap() != null && refClassMap.GetTypeColumnMap() == forColMap)
{
realRefClassMap = refClassMap.DomainMap.MustGetClassMap(value.GetType());
value = realRefClassMap.TypeValue;
}
else
{
idPropertyMap = refClassMap.MustGetPropertyMapForColumnMap(forColMap);
value = om.GetPropertyValue(value, idPropertyMap.Name);
}
}
}
}
}
// if (dataType == DbType.AnsiString || dataType == DbType.AnsiStringFixedLength || dataType == DbType.String || dataType == DbType.StringFixedLength)
// {
// if (columnMap.Precision == 0 || columnMap.Precision >= 4000)
// {
// compareOp = "LIKE";
// }
// }
param.Value = value;
}
示例10: CreateInverseProperty
private void CreateInverseProperty(IPropertyMap propertyMap, Hashtable newInverseProperties)
{
if (propertyMap.ReferenceType.Equals(ReferenceType.None))
return;
if (propertyMap.GetInversePropertyMap() != null)
return;
if (propertyMap.NoInverseManagement)
return;
if (propertyMap.GetTableMap() == null)
return;
IClassMap refClassMap = propertyMap.MustGetReferencedClassMap();
if (!(refClassMap.ClassType.Equals(ClassType.Class) || refClassMap.ClassType.Equals(ClassType.Default)))
return;
string inverseName = propertyMap.Inverse;
if (inverseName == "")
{
inverseName = "NPersistInverseOf" + propertyMap.ClassMap.Name + propertyMap.Name;
propertyMap.Inverse = inverseName;
}
IPropertyMap inversePropertyMap = new PropertyMap(inverseName);
string dataType = propertyMap.ClassMap.GetFullName();
inversePropertyMap.Inverse = propertyMap.Name;
inversePropertyMap.InheritInverseMappings = true;
propertyMap.InheritInverseMappings = false;
inversePropertyMap.Accessibility = AccessibilityType.ProtectedAccess;
inversePropertyMap.IsGenerated = true;
switch (propertyMap.ReferenceType)
{
case ReferenceType.ManyToMany:
inversePropertyMap.ReferenceType = ReferenceType.ManyToMany;
inversePropertyMap.ItemType = dataType;
inversePropertyMap.IsCollection = true;
inversePropertyMap.IsSlave = !propertyMap.IsSlave;
break;
case ReferenceType.ManyToOne:
inversePropertyMap.ReferenceType = ReferenceType.OneToMany;
inversePropertyMap.DataType = dataType;
inversePropertyMap.IsSlave = false;
propertyMap.IsSlave = true;
break;
case ReferenceType.OneToMany:
inversePropertyMap.ReferenceType = ReferenceType.ManyToOne;
inversePropertyMap.ItemType = dataType;
inversePropertyMap.IsCollection = true;
inversePropertyMap.IsSlave = true;
propertyMap.IsSlave = false;
break;
case ReferenceType.OneToOne:
inversePropertyMap.ReferenceType = ReferenceType.OneToOne;
inversePropertyMap.DataType = dataType;
inversePropertyMap.IsSlave = !propertyMap.IsSlave;
if (!propertyMap.IsSlave)
inversePropertyMap.IsNullable = true;
break;
}
if (!newInverseProperties.ContainsKey(refClassMap))
newInverseProperties[refClassMap] = new ArrayList();
IList propertiesForClass = (IList) newInverseProperties[refClassMap];
propertiesForClass.Add(inversePropertyMap);
}
示例11: GetSelectManyOnePropertyStatement
protected virtual string GetSelectManyOnePropertyStatement(object obj, IPropertyMap propertyMap, IList idColumns, IList typeColumns, Hashtable hashPropertyColumnMap, IList parameters)
{
string colName = "";
IColumnMap columnMap;
IClassMap classMap;
IPropertyMap refPropertyMap;
ITableMap tableMap;
ITableMap rootTableMap;
IColumnMap idColumnMap;
IPropertyMap myPropertyMap;
IColumnMap myColumnMap;
ITableMap myTableMap;
IColumnMap addIdColumnMap;
IColumnMap addMyColumnMap;
ITableMap addMyTableMap;
IColumnMap typeColumnMap;
IPropertyMap orderByMap;
string paramName = "";
classMap = propertyMap.MustGetReferencedClassMap();
IClassMap rootClassMap = classMap;
rootTableMap = classMap.MustGetTableMap();
tableMap = propertyMap.MustGetTableMap();
if (tableMap != rootTableMap)
{
bool done = false;
while (done == false && rootClassMap.InheritanceType != InheritanceType.ConcreteTableInheritance)
{
done = true;
IClassMap super = rootClassMap.GetInheritedClassMap();
if (super != null)
{
if (super.MustGetTableMap() == rootTableMap)
{
rootClassMap = super ;
done = false;
}
}
}
if (rootClassMap == null)
{
rootClassMap = classMap;
}
}
SqlSelectStatement select = new SqlSelectStatement(tableMap.SourceMap) ;
SqlTableAlias table = select.GetSqlTableAlias(tableMap);
idColumnMap = propertyMap.GetIdColumnMap();
SqlColumnAlias idColumn = table.GetSqlColumnAlias(idColumnMap);
myTableMap = idColumnMap.MustGetPrimaryKeyTableMap();
myColumnMap = idColumnMap.MustGetPrimaryKeyColumnMap();
if (myTableMap == null)
throw new MappingException("TableMap '" + idColumnMap.PrimaryKeyTable + "' Not Found!"); // do not localize
if (myColumnMap == null)
throw new MappingException("ColumnMap '" + idColumnMap.PrimaryKeyColumn + "' Not Found!"); // do not localize
SqlTableAlias rootTable = table;
if (tableMap != rootTableMap)
{
rootTable = select.GetSqlTableAlias(rootTableMap, "NPersistRootTable");
}
SqlTableAlias myTable;
SqlColumnAlias myColumn;
IObjectManager om;
orderByMap = propertyMap.GetOrderByPropertyMap();
//foreach (IPropertyMap iRefPropertyMap in rootClassMap.GetPrimaryPropertyMaps())
foreach (IPropertyMap iRefPropertyMap in rootClassMap.GetAllPropertyMaps())
{
refPropertyMap = iRefPropertyMap;
if (refPropertyMap.IsCollection)
{
if (this.Context.PersistenceManager.GetListCountLoadBehavior(LoadBehavior.Default, refPropertyMap) == LoadBehavior.Eager)
{
if (refPropertyMap.ReferenceType != ReferenceType.None)
{
ITableMap listTableMap = refPropertyMap.GetTableMap();
ISourceMap listSourceMap = listTableMap.SourceMap;
SqlSelectStatement subSelect = new SqlSelectStatement(listSourceMap);
SqlTableAlias listTable = subSelect.GetSqlTableAlias(listTableMap, "t" + select.GetNextTableAliasIndex());
SqlCountFunction count = new SqlCountFunction();
subSelect.SqlSelectClause.AddSqlAliasSelectListItem(count);
subSelect.SqlFromClause.AddSqlAliasTableSource(listTable);
foreach (IColumnMap fkIdColumnMap in refPropertyMap.GetAllIdColumnMaps())
{
IColumnMap pkIdColumnMap = fkIdColumnMap.MustGetPrimaryKeyColumnMap();
SqlColumnAlias fkIdColumn = listTable.GetSqlColumnAlias(fkIdColumnMap);
//.........这里部分代码省略.........
示例12: ManageReferenceValue
//if value is a list, values in list come in the same order as columns are returned from propertymap.refClassMap.GetIdentityCols! garantueed order !
//type column value must have been extracted from list in advance and should be passed to discriminator param
public virtual object ManageReferenceValue(object obj, IPropertyMap propertyMap, object value, object discriminator)
{
IClassMap refClassMap;
IPropertyMap mapToId;
if (!(propertyMap.ReferenceType == ReferenceType.None))
{
if (value != null)
{
refClassMap = propertyMap.MustGetReferencedClassMap();
if (discriminator != null)
{
try
{
discriminator = discriminator.ToString() ;
}
catch { discriminator = ""; }
refClassMap = refClassMap.GetSubClassWithTypeValue((string) discriminator);
if (refClassMap == null)
throw new NPersistException("Could not find class map with type value '" + (string) discriminator + "'");
}
//TODO: bug if one slave prop in a subclass references another subclass in single table inheritance
IColumnMap propertyColumnMap = propertyMap.GetColumnMap();
IColumnMap inverseColumnMap = propertyColumnMap.MustGetPrimaryKeyColumnMap();
mapToId = refClassMap.MustGetPropertyMapForColumnMap(inverseColumnMap);
if (mapToId.IsIdentity)
value = this.Context.GetObjectById(value, this.Context.AssemblyManager.MustGetTypeFromClassMap(refClassMap), true);
else
value = this.Context.GetObjectByKey(mapToId.Name, Convert.ToString(value), obj.GetType().GetProperty(propertyMap.Name).PropertyType);
}
}
return value;
}