Fluent nhibernate ICompositeUserType的列名是否可以在FluentNHibernate约定中进行控制?
我创建了一个Fluent nhibernate ICompositeUserType的列名是否可以在FluentNHibernate约定中进行控制?,fluent-nhibernate,Fluent Nhibernate,我创建了一个IUserTypeConvention约定,在匹配类型的所有属性上使用ICompositeUserType实现: public abstract class CompositeUserTypeConvention<TUserType> : IUserTypeConvention where TUserType : ICompositeUserType, new() { public virtual void Accept(IAcceptanceC
IUserTypeConvention
约定,在匹配类型的所有属性上使用ICompositeUserType
实现:
public abstract class CompositeUserTypeConvention<TUserType>
: IUserTypeConvention
where TUserType : ICompositeUserType, new()
{
public virtual void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
{
var userType = new TUserType();
criteria.Expect(x => x.Type == userType.ReturnedClass);
}
public virtual void Apply(IPropertyInstance instance)
{
instance.CustomType<TUserType>();
}
}
公共抽象类CompositeUserTypeConvention
:IUserTypeConvention
其中TUserType:ICompositeUserType,new()
{
公共虚拟无效接受(IAcceptanceCriteria标准)
{
var userType=new TUserType();
Expect(x=>x.Type==userType.ReturnedClass);
}
公共虚拟无效应用(IPropertyInstance实例)
{
CustomType();
}
}
应用此方法时,FluentNHibernate使用{memberpropertyname}{compositepropertyname}
的约定为复合类型的每个属性生成列名
对于属性为Amount
和Currency
的组合类型如Money
,如果我的实体上有一个名为Price
的Money
类型的属性,则预期的列称为Price\u Currency
和Price\u Amount
我想更改此约定以删除下划线,但我不知道如何或是否可能。CustomType()
方法有一个重载,该重载接受columnPrefix
作为参数。默认行为是将属性名+“389;”作为此值传递。明确指定该值会得到所需的结果:
public virtual void Apply(IPropertyInstance instance)
{
instance.CustomType<TUserType>(instance.Name);
}
公共虚拟无效应用(IPropertyInstance实例)
{
instance.CustomType(instance.Name);
}
方法的CustomType()
有一个重载,它接受列前缀作为参数。默认行为是将属性名+“389;”作为此值传递。明确指定该值会得到所需的结果:
public virtual void Apply(IPropertyInstance instance)
{
instance.CustomType<TUserType>(instance.Name);
}
公共虚拟无效应用(IPropertyInstance实例)
{
instance.CustomType(instance.Name);
}
在FluentNHibernate的当前版本中,此重载似乎已被删除。有关当前最新的答案,请参阅。在FluentNHibernate的当前版本中,此重载似乎已被删除。有关当前最新的答案,请参阅。