做實體的我設置ID與ConventionBuilder我有以下流利配置如何在功能NHibernate
var sessionFactory = Fluently.Configure()
.Database(configuration)
.Mappings(arg =>
{
var autoMap = AutoMap.Source(typeSource);
foreach (var convention in typeSource.GetConventions())
{
autoMap.Conventions.Add(convention);
}
autoMap.BuildMappings();
})
.BuildSessionFactory();
我用的FluentNHibernate.ITypeSource
也有一個方法GetConventions
,它返回System.Collections.Generic.IEnumerable<FluentNHibernate.Conventions.IConvention>
一個實例(typeSource
)。
GetConventions
的結果然後被用於注入到FluentNHibernate.Automapping.Automap
的Conventions
(在流暢配置的方法Mappings
中)。
的GetConventions
具體實現看起來像
public override System.Collections.Generic.IEnumerable<FluentNHibernate.Conventions.IConvention> GetConventions()
{
yield return FluentNHibernate.Conventions.Helpers.ConventionBuilder.Property.When(
arg => arg.Expect(f => f.Type == typeof (string)),
arg => arg.CustomType<CUSTOMTYPE>()
);
}
我也想介紹一個約定注入基礎上,EntityType
一個ID,我已經嘗試做這樣的:
yield return FluentNHibernate.Conventions.Helpers.ConventionBuilder.Class.When(
arg => arg.Expect(f => f.EntityType == typeof (ENTITYTYPE)),
arg => arg.Id // does not work, as .Id is readonly
);
那麼,如何在ConventionBuilder中注入ID,也可能是CombinedID?
編輯:
我也試了這一點,但遺憾的是在應用路徑(var a = 1;
)斷點永遠不會達到:
yield return FluentNHibernate.Conventions.Helpers.ConventionBuilder.Id.When(
arg => arg.Expect(f => f.EntityType == typeof(ENTITYTYPE)),
arg =>
{
var a = 1;
}
);