Fluent NHibernate set all IDs to assigned
I know I can manually set each Id property to assigned using Assigned()
.
Is there开发者_高级运维 any way of applying this globally, as I want to do it on every entity?
Sure, just register FluentNHibernate convention like this:
public class AssignedIdConvention : IIdConvention
{
public void Apply(IIdentityInstance instance)
{
instance.GeneratedBy.Assigned();
}
}
Registration goes like this:
Fluently.Configure()
.Mappings(...)
.Conventions.Add<AssignedIdConvention>()
精彩评论