public static void MapNonPrimitiveTypes <T>(this ClasslikeMapBase <T> dynamicMap, string tableName, IList <PropertyInfo> nonPrimitiveColumns, bool nullableReference) where T : DynamicClass { foreach (var column in nonPrimitiveColumns) { var types = new List <Type>(); types.Add(typeof(T)); types.Add(column.PropertyType); var method = typeof(FluentNHibernate.Reveal).GetMethods().Where(m => m.Name == "Member").Last(); var generic = method.MakeGenericMethod(typeof(T), column.PropertyType); dynamic tmp = generic.Invoke(dynamicMap, new object[] { column.Name }); if (nullableReference == false) // this is always false at the moment. { if (DynamicClass.SetIdsToBeAssigned == true) //means we are doing a backup { dynamicMap.References(tmp) .Nullable() .NotFound.Ignore() .ForeignKey("FK_" + tableName + "_" + column.Name) // Will prevent deleting child object without deleting parent object .LazyLoad(Laziness.False); } else { dynamicMap.References(tmp) .Not.Nullable() .NotFound.Exception() .ForeignKey("FK_" + tableName + "_" + column.Name) // Will prevent deleting child object without deleting parent object .LazyLoad(Laziness.False); } } else { //TODO: Should this be nullable? Need to find examples of when it comes here. dynamicMap.References(tmp) //.Not.Nullable() .Nullable() .Cascade.None() .NotFound.Ignore() .LazyLoad(Laziness.False); } } }
/// <summary> /// Implementation for late binding generic call. Shouldn't be called directly Called through reflection. /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TChild"></typeparam> /// <param name="mapping"></param> /// <param name="property"></param> /// <param name="ownership"></param> private static void MapReferenceImplementation <T, TChild>(ClasslikeMapBase <T> mapping, PropertyInfo property, Ownership ownership) { var part = mapping.References(CreateReferenceExpression <T, TChild>(property)); if (ownership == Ownership.None) { part.Cascade.None(); } else if (ownership == Ownership.Exclusive) { part.Cascade.All(); } else if (ownership == Ownership.Shared) { part.Cascade.SaveUpdate(); } part.Column(property.Name + "ID"); //part.ForeignKey("FK_" + typeof(T).Name + "_" + typeof(TChild).Name); }
/// <summary> /// /// </summary> /// <param name="map"></param> /// <param name="hierarchyTableName"></param> /// <typeparam name="T"></typeparam> public static void TreeMap <T>(this ClasslikeMapBase <T> map, string hierarchyTableName) where T : TreeNode <T> { map.References(x => x.Parent) .LazyLoad() .Nullable() .Column("PARENT_ID"); map.HasMany(x => x.Children) .Access.ReadOnlyPropertyThroughCamelCaseField() .Cascade.All() .Inverse() .AsSet() .LazyLoad() .BatchSize(250) .KeyColumn("PARENT_ID"); map.HasManyToMany(x => x.Ancestors) .Access.ReadOnlyPropertyThroughCamelCaseField() .Cascade.None() .AsSet() .LazyLoad() .BatchSize(250) .Table(hierarchyTableName) .ParentKeyColumn("CHILD_ID") .ChildKeyColumn("PARENT_ID") .ForeignKeyConstraintNames(string.Format("FK_{0}_CHILD", hierarchyTableName), null); map.HasManyToMany(x => x.Descendants) .Access.ReadOnlyPropertyThroughCamelCaseField() .Cascade.All() .Inverse() .AsSet() .LazyLoad() .BatchSize(250) .Table(hierarchyTableName) .ParentKeyColumn("PARENT_ID") .ChildKeyColumn("CHILD_ID") .ForeignKeyConstraintNames(string.Format("FK_{0}_PARENT", hierarchyTableName), null); }
public static ManyToOnePart <TOther> ReferenceIndex <T, TOther>(this ClasslikeMapBase <T> map, Expression <Func <T, TOther> > memberExpression) { return(map.References(memberExpression, $"{ExpressionHelper.GetPropertyName(memberExpression)}Id").Index($"Idx{ExpressionHelper.GetPropertyName(memberExpression)}")); }