void ContentDetailCustomization(IClassMapper <ContentDetail> ca) { ca.Table(tablePrefix + "Detail"); ca.Lazy(false); ca.Cache(cm => { cm.Usage(CacheUsage.NonstrictReadWrite); cm.Region(cacheRegion); }); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.ManyToOne(x => x.EnclosingItem, cm => { cm.Column("ItemID"); cm.NotNullable(true); cm.Fetch(FetchKind.Select); cm.Lazy(LazyRelation.Proxy); }); ca.ManyToOne(x => x.EnclosingCollection, cm => { cm.Column("DetailCollectionID"); cm.Fetch(FetchKind.Select); cm.Lazy(LazyRelation.Proxy); }); ca.Property(x => x.ValueTypeKey, cm => { cm.Column("Type"); cm.Length(10); }); ca.Property(x => x.Name, cm => { cm.Length(50); }); ca.Property(x => x.Meta, cm => { cm.Type(NHibernateUtil.StringClob); cm.Length(stringLength); }); ca.Property(x => x.BoolValue, cm => { }); ca.Property(x => x.DateTimeValue, cm => { }); ca.Property(x => x.IntValue, cm => { }); ca.Component(x => x.LinkedItem, cm => { cm.Property(cr => cr.ID, pm => pm.Column("LinkValue")); }); //ca.ManyToOne(x => x.LinkedItem, cm => { cm.Column("LinkValue"); cm.NotFound(NotFoundMode.Ignore); cm.Fetch(FetchKind.Select); cm.Lazy(LazyRelation.Proxy); cm.Cascade(Cascade.None); }); ca.Property(x => x.DoubleValue, cm => { }); // if you are using Oracle10g and get // ORA-01461: can bind a LONG value only for insert into a LONG column // use the following line instead of the the later one (NOTICE both apply to the same property) // ca.Property(x => x.StringValue, cm => { cm.Type(NHibernateUtil.AnsiString); cm.Length(stringLength); }); ca.Property(x => x.StringValue, cm => { cm.Type(NHibernateUtil.StringClob); cm.Length(stringLength); }); ca.Property(x => x.ObjectValue, cm => { cm.Column("Value"); cm.Type(NHibernateUtil.Serializable); cm.Length(ConfigurationBuilder.BlobLength); }); }
void FileSystemItemCustomization(IClassMapper<FileSystemItem> ca) { ca.Table(tablePrefix + "FSItem"); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.Lazy(false); ca.Cache(cm => { cm.Usage(CacheUsage.NonstrictReadWrite); }); ca.Component(x => x.Path, cm => { cm.Property(x => x.Parent, ccm => { ccm.Length(1024); }); cm.Property(x => x.Name, ccm => { ccm.Length(255); }); cm.Property(x => x.IsDirectory, ccm => { }); }); ca.Property(x => x.Created, cm => { cm.NotNullable(true); }); ca.Property(x => x.Updated, cm => { cm.NotNullable(true); }); ca.Property(x => x.Length, cm => { }); //ca.Bag(x => x.Chunks, cm => // { // cm.Key(k => k.Column("FileID")); // cm.Inverse(true); // cm.Cascade(Cascade.All); // cm.OrderBy(ci => ci.Offset); // cm.Lazy(CollectionLazy.Extra); // }, cr => cr.OneToMany()); }
void FileSystemItemCustomization(IClassMapper <FileSystemItem> ca) { ca.Table(tablePrefix + "FSItem"); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.Lazy(false); ca.Cache(cm => { cm.Usage(CacheUsage.NonstrictReadWrite); }); ca.Component(x => x.Path, cm => { cm.Property(x => x.Parent, ccm => { ccm.Length(1024); }); cm.Property(x => x.Name, ccm => { ccm.Length(255); }); cm.Property(x => x.IsDirectory, ccm => { }); }); ca.Property(x => x.Created, cm => { cm.NotNullable(true); }); ca.Property(x => x.Updated, cm => { cm.NotNullable(true); }); ca.Property(x => x.Length, cm => { }); //ca.Bag(x => x.Chunks, cm => // { // cm.Key(k => k.Column("FileID")); // cm.Inverse(true); // cm.Cascade(Cascade.All); // cm.OrderBy(ci => ci.Offset); // cm.Lazy(CollectionLazy.Extra); // }, cr => cr.OneToMany()); }
private void BucketCustomization(IClassMapper<Bucket> ca) { ca.Table(tablePrefix + "StatisticsBucket"); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.Lazy(false); ca.Property(x => x.PageID, cm => { cm.NotNullable(true); }); ca.Property(x => x.TimeSlot, cm => { cm.NotNullable(true); }); ca.Property(x => x.Views, cm => { cm.NotNullable(true); }); }
void FileSystemChunkCustomization(IClassMapper<FileSystemChunk> ca) { ca.Table(tablePrefix + "FSChunk"); ca.Lazy(false); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.ManyToOne(x => x.BelongsTo, m => { m.Column("FileID"); }); ca.Property(x => x.Offset, cm => { }); ca.Property(cm => cm.Data, cm => { cm.Type(NHibernateUtil.BinaryBlob); cm.Length(ConfigurationBuilder.BlobLength); cm.Lazy(false); }); }
void AuthorizedRoleCustomization(IClassMapper <AuthorizedRole> ca) { ca.Table(tablePrefix + "AllowedRole"); ca.Lazy(false); ca.Cache(cm => { cm.Usage(CacheUsage.NonstrictReadWrite); cm.Region(cacheRegion); }); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.ManyToOne(x => x.EnclosingItem, cm => { cm.Column("ItemID"); cm.NotNullable(true); }); ca.Property(x => x.Role, cm => { cm.Length(50); cm.NotNullable(true); }); }
private void BucketCustomization(IClassMapper <Bucket> ca) { ca.Table(tablePrefix + "StatisticsBucket"); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.Lazy(false); ca.Property(x => x.PageID, cm => { cm.NotNullable(true); }); ca.Property(x => x.TimeSlot, cm => { cm.NotNullable(true); }); ca.Property(x => x.Views, cm => { cm.NotNullable(true); }); }
void FileSystemChunkCustomization(IClassMapper <FileSystemChunk> ca) { ca.Table(tablePrefix + "FSChunk"); ca.Lazy(false); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.ManyToOne(x => x.BelongsTo, m => { m.Column("FileID"); }); ca.Property(x => x.Offset, cm => { }); ca.Property(cm => cm.Data, cm => { cm.Type(NHibernateUtil.BinaryBlob); cm.Length(ConfigurationBuilder.BlobLength); cm.Lazy(false); }); }
private void StatisticCustomization(IClassMapper<Statistic> ca) { ca.Table(tablePrefix + "Statistics"); ca.ComposedId(x => { x.Property(y => y.TimeSlot); x.Property(y => y.PageID); }); //ca.Id(x => new { x.TimeSlot, x.PageID }, cm => { cm.Generator(Generators.Assigned); }); ca.Lazy(false); ca.Property(x => x.TimeSlot, cm => { cm.NotNullable(true); }); ca.Property(x => x.Views, cm => { cm.NotNullable(true); }); }
private void StatisticCustomization(IClassMapper <Statistic> ca) { ca.Table(tablePrefix + "Statistics"); ca.ComposedId(x => { x.Property(y => y.TimeSlot); x.Property(y => y.PageID); }); //ca.Id(x => new { x.TimeSlot, x.PageID }, cm => { cm.Generator(Generators.Assigned); }); ca.Lazy(false); ca.Property(x => x.TimeSlot, cm => { cm.NotNullable(true); }); ca.Property(x => x.Views, cm => { cm.NotNullable(true); }); }
void ContentDetailCustomization(IClassMapper <ContentDetail> ca) { ca.Table(tablePrefix + "Detail"); ca.Lazy(false); ca.Cache(cm => { cm.Usage(CacheUsage.NonstrictReadWrite); }); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.ManyToOne(x => x.EnclosingItem, cm => { cm.Column("ItemID"); cm.NotNullable(true); cm.Fetch(FetchKind.Select); }); ca.ManyToOne(x => x.EnclosingCollection, cm => { cm.Column("DetailCollectionID"); cm.Fetch(FetchKind.Select); cm.Lazy(LazyRelation.Proxy); }); ca.Property(x => x.ValueTypeKey, cm => { cm.Column("Type"); cm.Length(10); }); ca.Property(x => x.Name, cm => { cm.Length(50); }); ca.Property(x => x.BoolValue, cm => { }); ca.Property(x => x.DateTimeValue, cm => { }); ca.Property(x => x.IntValue, cm => { }); ca.ManyToOne(x => x.LinkedItem, cm => { cm.Column("LinkValue"); cm.Lazy(LazyRelation.Proxy); cm.Cascade(Cascade.None); }); ca.Property(x => x.DoubleValue, cm => { }); ca.Property(x => x.StringValue, cm => { cm.Type(NHibernateUtil.StringClob); cm.Length(stringLength); }); ca.Property(x => x.ObjectValue, cm => { cm.Column("Value"); cm.Type(NHibernateUtil.Serializable); cm.Length(2147483647); }); }
void DetailCollectionCustomization(IClassMapper <DetailCollection> ca) { ca.Table(tablePrefix + "DetailCollection"); ca.Lazy(false); ca.Cache(cm => { cm.Usage(CacheUsage.NonstrictReadWrite); cm.Region(cacheRegion); }); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.ManyToOne(x => x.EnclosingItem, cm => { cm.Column("ItemID"); cm.Fetch(FetchKind.Select); cm.Lazy(LazyRelation.Proxy); }); ca.Property(x => x.Name, cm => { cm.Length(50); cm.NotNullable(true); }); ca.Bag(x => x.Details, cm => { cm.Key(k => k.Column("DetailCollectionID")); cm.Inverse(true); cm.Cascade(Cascade.All | Cascade.DeleteOrphans); cm.Lazy(CollectionLazy.Lazy); cm.Fetch(CollectionFetchMode.Select); cm.Cache(m => { m.Usage(CacheUsage.NonstrictReadWrite); m.Region(cacheRegion); }); }, cr => cr.OneToMany()); }
void ContentVersionCustomization(IClassMapper <ContentVersion> ca) { ca.Table(tablePrefix + "Version"); ca.Lazy(false); ca.Cache(cm => { cm.Usage(CacheUsage.NonstrictReadWrite); cm.Region(cacheRegion); }); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.Component(x => x.Master, cm => { cm.Property(cr => cr.ID, pm => pm.Column("MasterID")); }); ca.Property(x => x.Title, xm => { }); ca.Property(x => x.Published, cm => { }); ca.Property(x => x.FuturePublish, cm => { }); ca.Property(x => x.Expired, cm => { }); ca.Property(x => x.VersionIndex, cm => { }); ca.Property(x => x.Saved, cm => { }); ca.Property(x => x.State, cm => { }); ca.Property(x => x.SavedBy, cm => { }); ca.Property(x => x.ItemCount, cm => { }); ca.Property(x => x.VersionDataXml, cm => { cm.Type(GetStringClobType()); cm.Length(stringLength); }); }
void ContentDetailCustomization(IClassMapper <ContentDetail> ca) { ca.Table(tablePrefix + "Detail"); ca.Lazy(false); ca.Cache(cm => { cm.Usage(CacheUsage.NonstrictReadWrite); cm.Region(cacheRegion); }); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.ManyToOne(x => x.EnclosingItem, cm => { cm.Column("ItemID"); cm.NotNullable(true); cm.Fetch(FetchKind.Select); cm.Lazy(LazyRelation.Proxy); }); ca.ManyToOne(x => x.EnclosingCollection, cm => { cm.Column("DetailCollectionID"); cm.Fetch(FetchKind.Select); cm.Lazy(LazyRelation.Proxy); }); ca.Property(x => x.ValueTypeKey, cm => { cm.Column("Type"); cm.Length(10); }); ca.Property(x => x.Name, cm => { cm.Length(50); }); ca.Property(x => x.Meta, cm => { cm.Type(GetStringClobType()); cm.Length(stringLength); }); ca.Property(x => x.BoolValue, cm => { }); ca.Property(x => x.DateTimeValue, cm => { }); ca.Property(x => x.IntValue, cm => { }); ca.Component(x => x.LinkedItem, cm => { cm.Property(cr => cr.ID, pm => pm.Column("LinkValue")); }); //ca.ManyToOne(x => x.LinkedItem, cm => { cm.Column("LinkValue"); cm.NotFound(NotFoundMode.Ignore); cm.Fetch(FetchKind.Select); cm.Lazy(LazyRelation.Proxy); cm.Cascade(Cascade.None); }); ca.Property(x => x.DoubleValue, cm => { }); ca.Property(x => x.StringValue, cm => { cm.Type(GetStringClobType()); cm.Length(stringLength); }); ca.Property(x => x.ObjectValue, cm => { cm.Column("Value"); cm.Type(NHibernateUtil.Serializable); cm.Length(ConfigurationBuilder.BlobLength); }); }
void ContentVersionCustomization(IClassMapper<ContentVersion> ca) { ca.Table(tablePrefix + "Version"); ca.Lazy(false); ca.Cache(cm => { cm.Usage(CacheUsage.NonstrictReadWrite); cm.Region(cacheRegion); }); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.Component(x => x.Master, cm => { cm.Property(cr => cr.ID, pm => pm.Column("MasterID")); }); ca.Property(x => x.Title, xm => { }); ca.Property(x => x.Published, cm => { }); ca.Property(x => x.FuturePublish, cm => { }); ca.Property(x => x.Expired, cm => { }); ca.Property(x => x.VersionIndex, cm => { }); ca.Property(x => x.Saved, cm => { }); ca.Property(x => x.State, cm => { }); ca.Property(x => x.SavedBy, cm => { }); ca.Property(x => x.ItemCount, cm => { }); ca.Property(x => x.VersionDataXml, cm => { cm.Type(NHibernateUtil.StringClob); cm.Length(stringLength); }); }
void AuthorizedRoleCustomization(IClassMapper<AuthorizedRole> ca) { ca.Table(tablePrefix + "AllowedRole"); ca.Lazy(false); ca.Cache(cm => { cm.Usage(CacheUsage.NonstrictReadWrite); cm.Region(cacheRegion); }); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.ManyToOne(x => x.EnclosingItem, cm => { cm.Column("ItemID"); cm.NotNullable(true); }); ca.Property(x => x.Role, cm => { cm.Length(50); cm.NotNullable(true); }); }
void DetailCollectionCustomization(IClassMapper<DetailCollection> ca) { ca.Table(tablePrefix + "DetailCollection"); ca.Lazy(false); ca.Cache(cm => { cm.Usage(CacheUsage.NonstrictReadWrite); cm.Region(cacheRegion); }); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.ManyToOne(x => x.EnclosingItem, cm => { cm.Column("ItemID"); cm.Fetch(FetchKind.Select); cm.Lazy(LazyRelation.Proxy); }); ca.Property(x => x.Name, cm => { cm.Length(50); cm.NotNullable(true); }); ca.Bag(x => x.Details, cm => { cm.Key(k => k.Column("DetailCollectionID")); cm.Inverse(true); cm.Cascade(Cascade.All | Cascade.DeleteOrphans); cm.Lazy(CollectionLazy.Lazy); cm.Fetch(CollectionFetchMode.Select); cm.Cache(m => { m.Usage(CacheUsage.NonstrictReadWrite); m.Region(cacheRegion); }); }, cr => cr.OneToMany()); }
void ContentDetailCustomization(IClassMapper<ContentDetail> ca) { ca.Table(tablePrefix + "Detail"); ca.Lazy(false); ca.Cache(cm => { cm.Usage(CacheUsage.NonstrictReadWrite); cm.Region(cacheRegion); }); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.ManyToOne(x => x.EnclosingItem, cm => { cm.Column("ItemID"); cm.NotNullable(true); cm.Fetch(FetchKind.Select); cm.Lazy(LazyRelation.Proxy); }); ca.ManyToOne(x => x.EnclosingCollection, cm => { cm.Column("DetailCollectionID"); cm.Fetch(FetchKind.Select); cm.Lazy(LazyRelation.Proxy); }); ca.Property(x => x.ValueTypeKey, cm => { cm.Column("Type"); cm.Length(10); }); ca.Property(x => x.Name, cm => { cm.Length(50); }); ca.Property(x => x.Meta, cm => { cm.Type(NHibernateUtil.StringClob); cm.Length(stringLength); }); ca.Property(x => x.BoolValue, cm => { }); ca.Property(x => x.DateTimeValue, cm => { }); ca.Property(x => x.IntValue, cm => { }); ca.Component(x => x.LinkedItem, cm => { cm.Property(cr => cr.ID, pm => pm.Column("LinkValue")); }); //ca.ManyToOne(x => x.LinkedItem, cm => { cm.Column("LinkValue"); cm.NotFound(NotFoundMode.Ignore); cm.Fetch(FetchKind.Select); cm.Lazy(LazyRelation.Proxy); cm.Cascade(Cascade.None); }); ca.Property(x => x.DoubleValue, cm => { }); // if you are using Oracle10g and get // ORA-01461: can bind a LONG value only for insert into a LONG column // use the following line instead of the the later one (NOTICE both apply to the same property) // ca.Property(x => x.StringValue, cm => { cm.Type(NHibernateUtil.AnsiString); cm.Length(stringLength); }); ca.Property(x => x.StringValue, cm => { cm.Type(NHibernateUtil.StringClob); cm.Length(stringLength); }); ca.Property(x => x.ObjectValue, cm => { cm.Column("Value"); cm.Type(NHibernateUtil.Serializable); cm.Length(ConfigurationBuilder.BlobLength); }); }
void ContentItemCustomization(IClassMapper<ContentItem> ca) { ca.Table(tablePrefix + "Item"); ca.Lazy(false); ca.Cache(cm => { cm.Usage(CacheUsage.NonstrictReadWrite); cm.Region(cacheRegion); }); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.Discriminator(cm => { cm.Column("Type"); cm.Type(NHibernateUtil.String); }); ca.Property(x => x.Created, cm => { }); ca.Property(x => x.Published, cm => { }); ca.Property(x => x.Updated, cm => { }); ca.Property(x => x.Expires, cm => { }); ca.Property(x => x.Name, cm => { cm.Length(250); }); ca.Property(x => x.ZoneName, cm => { cm.Length(50); }); ca.Property(x => x.TemplateKey, cm => { cm.Length(50); }); ca.Property(x => x.TranslationKey, cm => { }); ca.Property(x => x.Title, cm => { cm.Length(250); }); ca.Property(x => x.SortOrder, cm => { }); ca.Property(x => x.Visible, cm => { }); ca.Property(x => x.SavedBy, cm => { cm.Length(50); }); ca.Property(x => x.State, cm => { }); ca.Property(x => x.ChildState, cm => { }); ca.Property(x => x.AncestralTrail, cm => { cm.Length(100); }); ca.Property(x => x.VersionIndex, cm => { }); ca.Property(x => x.AlteredPermissions, cm => { }); //ca.ManyToOne(x => x.VersionOf, cm => { cm.Column("VersionOfID"); cm.Lazy(LazyRelation.Proxy); cm.Fetch(FetchKind.Select); }); //ca.Property(x => x.VersionOf, cm => //{ // cm.Column("VersionOfID"); // cm.Type<ContentRelationFactory>(); //}); ca.Component(x => x.VersionOf, cm => { cm.Property(cr => cr.ID, pm => pm.Column("VersionOfID")); }); ca.ManyToOne(x => x.Parent, cm => { cm.Column("ParentID"); cm.Lazy(LazyRelation.Proxy); cm.Fetch(FetchKind.Select); }); ca.Bag(x => x.Children, cm => { cm.Key(k => k.Column("ParentID")); cm.Inverse(true); cm.Type<ContentItemListFactory<ContentItem>>(); cm.Cascade(childrenCascade); cm.OrderBy(ci => ci.SortOrder); cm.Lazy(childrenLaziness); if (childrenBatch) cm.BatchSize(batchSize ?? 10); cm.Cache(m => { m.Usage(CacheUsage.NonstrictReadWrite); m.Region(cacheRegion); }); }, cr => cr.OneToMany()); ca.Bag(x => x.Details, cm => { cm.Key(k => k.Column("ItemID")); cm.Inverse(true); cm.Type<ContentListFactory<ContentDetail>>(); cm.Cascade(Cascade.All | Cascade.DeleteOrphans); cm.Fetch(CollectionFetchMode.Select); cm.Lazy(CollectionLazy.Lazy); cm.BatchSize(batchSize ?? 10); cm.Cache(m => { m.Usage(CacheUsage.NonstrictReadWrite); m.Region(cacheRegion); }); cm.Where("DetailCollectionID IS NULL"); }, cr => cr.OneToMany()); ca.Bag(x => x.DetailCollections, cm => { cm.Key(k => k.Column("ItemID")); cm.Inverse(true); cm.Type<ContentListFactory<DetailCollection>>(); cm.Cascade(Cascade.All | Cascade.DeleteOrphans); cm.Fetch(CollectionFetchMode.Select); cm.Lazy(CollectionLazy.Lazy); cm.BatchSize(batchSize ?? 10); cm.Cache(m => { m.Usage(CacheUsage.NonstrictReadWrite); m.Region(cacheRegion); }); }, cr => cr.OneToMany()); ca.Bag(x => x.AuthorizedRoles, cm => { cm.Key(k => k.Column("ItemID")); cm.Inverse(true); cm.Cascade(Cascade.All | Cascade.DeleteOrphans); cm.Fetch(CollectionFetchMode.Select); cm.Lazy(CollectionLazy.Lazy); cm.BatchSize(batchSize ?? 25); cm.Cache(m => { m.Usage(CacheUsage.NonstrictReadWrite); m.Region(cacheRegion); }); }, cr => cr.OneToMany()); }
/// <summary> /// 简单映射方法 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="inputMapper"></param> internal static void EntityMappingMethod <X>(IClassMapper <X> inputValue) where X : BaseEntity { //开启二级缓存 inputValue.Cache(k => { k.Usage(CacheUsage.ReadWrite); }); //优先关闭延迟加载 inputValue.Lazy(false); //绑定Id //设定为自增主键 inputValue.Id(k => k.Id, map => map.Generator(Generators.Identity)); inputValue.EntityName(typeof(X).Name); Type useType = typeof(X); //获取属性设置器类型 Type useMapperMehtodType = typeof(EntityAutoMappingUtility); //设置用方法 MethodInfo useBasePropertyInfo = null; MethodInfo useBaseBagInfo = null; MethodInfo useBaseManyToOneInfo = null; MethodInfo useBaseBagManyInfo = null; useBasePropertyInfo = useMapperMehtodType.GetMethod(m_strUsePropertyMethodName, BindingFlags.Static | BindingFlags.NonPublic); useBaseBagInfo = useMapperMehtodType.GetMethod(m_strUseBagMethodName, BindingFlags.Static | BindingFlags.NonPublic); useBaseManyToOneInfo = useMapperMehtodType.GetMethod(m_strUseManyToOneMethodName, BindingFlags.Static | BindingFlags.NonPublic); useBaseBagManyInfo = useMapperMehtodType.GetMethod(m_strUseBagManyMethodName, BindingFlags.Static | BindingFlags.NonPublic); var allProperties = useType.GetProperties(); //表达式变量 ParameterExpression target = null; Expression getPropertyValue = null; MethodInfo realUsePopertyMethod = null; //遍历属性 foreach (var onePropertie in allProperties) { //跳过Id if (onePropertie.Name.Equals(m_strUseIdName)) { continue; } //选取合适的特性 if (onePropertie.CanRead && onePropertie.CanWrite && onePropertie.GetMethod.IsVirtual && onePropertie.SetMethod.IsVirtual) { //获取附加属性 PropertyAttribute useAttribute = onePropertie.GetCustomAttribute(typeof(PropertyAttribute)) as PropertyAttribute; //制作表达式 target = Expression.Parameter(useType); getPropertyValue = Expression.Property(target, onePropertie); //one - Many 行为 if (onePropertie.PropertyType.IsGenericCollection() && onePropertie.PropertyType.IsInterface && onePropertie.PropertyType.DetermineCollectionElementType().IsSubclassOf(m_baseEntityType)) { //bag if (onePropertie.PropertyType.GetGenericTypeDefinition() == m_baseIEnumerable) { //区分ManyToMany if (null != useAttribute && useAttribute.IfIsManyToMany) { realUsePopertyMethod = useBaseBagManyInfo.MakeGenericMethod(new Type[] { useType, onePropertie.PropertyType.DetermineCollectionElementType() }); //不同的执行分支 realUsePopertyMethod.Invoke(null, new object[] { inputValue, Expression.Lambda(getPropertyValue, target), !useAttribute.IfIsManyToManyControl }); continue; } else { realUsePopertyMethod = useBaseBagInfo.MakeGenericMethod(new Type[] { useType, onePropertie.PropertyType.DetermineCollectionElementType() }); } } else { continue; } } //Many - one 行为 else if (onePropertie.PropertyType.IsSubclassOf(m_baseEntityType)) { realUsePopertyMethod = useBaseManyToOneInfo.MakeGenericMethod(new Type[] { useType, onePropertie.PropertyType }); } //标准行为 else if (!((onePropertie.PropertyType.IsGenericCollection() && onePropertie.PropertyType.IsInterface))) { realUsePopertyMethod = useBasePropertyInfo.MakeGenericMethod(new Type[] { useType, onePropertie.PropertyType }); } //不处理行为 else { continue; } realUsePopertyMethod.Invoke(null, new object[] { inputValue, Expression.Lambda(getPropertyValue, target) }); } else { continue; } } }
void ContentItemCustomization(IClassMapper <ContentItem> ca) { ca.Table(tablePrefix + "Item"); ca.Lazy(false); ca.Cache(cm => { cm.Usage(CacheUsage.NonstrictReadWrite); cm.Region(cacheRegion); }); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.Discriminator(cm => { cm.Column("Type"); cm.Type(NHibernateUtil.String); }); ca.Property(x => x.Created, cm => { }); ca.Property(x => x.Published, cm => { }); ca.Property(x => x.Updated, cm => { }); ca.Property(x => x.Expires, cm => { }); ca.Property(x => x.Name, cm => { cm.Length(250); }); ca.Property(x => x.ZoneName, cm => { cm.Length(50); }); ca.Property(x => x.TemplateKey, cm => { cm.Length(50); }); ca.Property(x => x.TranslationKey, cm => { }); ca.Property(x => x.Title, cm => { cm.Length(250); }); ca.Property(x => x.SortOrder, cm => { }); ca.Property(x => x.Visible, cm => { }); ca.Property(x => x.SavedBy, cm => { cm.Length(50); }); ca.Property(x => x.State, cm => { }); ca.Property(x => x.ChildState, cm => { }); ca.Property(x => x.AncestralTrail, cm => { cm.Length(100); }); ca.Property(x => x.VersionIndex, cm => { }); ca.Property(x => x.AlteredPermissions, cm => { }); //ca.ManyToOne(x => x.VersionOf, cm => { cm.Column("VersionOfID"); cm.Lazy(LazyRelation.Proxy); cm.Fetch(FetchKind.Select); }); //ca.Property(x => x.VersionOf, cm => //{ // cm.Column("VersionOfID"); // cm.Type<ContentRelationFactory>(); //}); ca.Component(x => x.VersionOf, cm => { cm.Property(cr => cr.ID, pm => pm.Column("VersionOfID")); }); ca.ManyToOne(x => x.Parent, cm => { cm.Column("ParentID"); cm.Lazy(LazyRelation.Proxy); cm.Fetch(FetchKind.Select); }); ca.Bag(x => x.Children, cm => { cm.Key(k => k.Column("ParentID")); cm.Inverse(true); cm.Type <ContentItemListFactory <ContentItem> >(); cm.Cascade(childrenCascade); cm.OrderBy(ci => ci.SortOrder); cm.Lazy(childrenLaziness); if (childrenBatch) { cm.BatchSize(batchSize ?? 10); } cm.Cache(m => { m.Usage(CacheUsage.NonstrictReadWrite); m.Region(cacheRegion); }); }, cr => cr.OneToMany()); ca.Bag(x => x.Details, cm => { cm.Key(k => k.Column("ItemID")); cm.Inverse(true); cm.Type <ContentListFactory <ContentDetail> >(); cm.Cascade(Cascade.All | Cascade.DeleteOrphans); cm.Fetch(CollectionFetchMode.Select); cm.Lazy(CollectionLazy.Lazy); cm.BatchSize(batchSize ?? 10); cm.Cache(m => { m.Usage(CacheUsage.NonstrictReadWrite); m.Region(cacheRegion); }); cm.Where("DetailCollectionID IS NULL"); }, cr => cr.OneToMany()); ca.Bag(x => x.DetailCollections, cm => { cm.Key(k => k.Column("ItemID")); cm.Inverse(true); cm.Type <DetailCollectionFactory>(); cm.Cascade(Cascade.All | Cascade.DeleteOrphans); cm.Fetch(CollectionFetchMode.Select); cm.Lazy(CollectionLazy.Lazy); cm.BatchSize(batchSize ?? 10); cm.Cache(m => { m.Usage(CacheUsage.NonstrictReadWrite); m.Region(cacheRegion); }); }, cr => cr.OneToMany()); ca.Bag(x => x.AuthorizedRoles, cm => { cm.Key(k => k.Column("ItemID")); cm.Inverse(true); cm.Cascade(Cascade.All | Cascade.DeleteOrphans); cm.Fetch(CollectionFetchMode.Select); cm.Lazy(CollectionLazy.Lazy); cm.BatchSize(batchSize ?? 25); cm.Cache(m => { m.Usage(CacheUsage.NonstrictReadWrite); m.Region(cacheRegion); }); }, cr => cr.OneToMany()); }
void ContentDetailCustomization(IClassMapper<ContentDetail> ca) { ca.Table(tablePrefix + "Detail"); ca.Lazy(false); ca.Cache(cm => { cm.Usage(CacheUsage.NonstrictReadWrite); }); ca.Id(x => x.ID, cm => { cm.Generator(Generators.Native); }); ca.ManyToOne(x => x.EnclosingItem, cm => { cm.Column("ItemID"); cm.NotNullable(true); cm.Fetch(FetchKind.Select); }); ca.ManyToOne(x => x.EnclosingCollection, cm => { cm.Column("DetailCollectionID"); cm.Fetch(FetchKind.Select); cm.Lazy(LazyRelation.Proxy); }); ca.Property(x => x.ValueTypeKey, cm => { cm.Column("Type"); cm.Length(10); }); ca.Property(x => x.Name, cm => { cm.Length(50); }); ca.Property(x => x.BoolValue, cm => { }); ca.Property(x => x.DateTimeValue, cm => { }); ca.Property(x => x.IntValue, cm => { }); ca.ManyToOne(x => x.LinkedItem, cm => { cm.Column("LinkValue"); cm.Lazy(LazyRelation.Proxy); cm.Cascade(Cascade.None); }); ca.Property(x => x.DoubleValue, cm => { }); ca.Property(x => x.StringValue, cm => { cm.Type(NHibernateUtil.StringClob); cm.Length(stringLength); }); ca.Property(x => x.ObjectValue, cm => { cm.Column("Value"); cm.Type(NHibernateUtil.Serializable); cm.Length(2147483647); }); }