NHibernate通用字典表映射
我的所有字典都有一个表:“Id,TypeId,Value”,所以对于特定的TypeId,我有一对:“Id+Value”,这是我的具体字典 我应该如何绘制地图NHibernate通用字典表映射,nhibernate,nhibernate-mapping,Nhibernate,Nhibernate Mapping,我的所有字典都有一个表:“Id,TypeId,Value”,所以对于特定的TypeId,我有一对:“Id+Value”,这是我的具体字典 我应该如何绘制地图 目前,我可以想象我将拥有一个抽象类字典和具体类:InvoiceTypeDictionary、PaymentTypeDictionary等(我可以将子类鉴别器设置为TypeId,就这样)。但是,有没有其他方法来避免必要的大量子类呢?我不确定值是什么 // InvoiceTypeMap : ClassMap<InvoiceType>
目前,我可以想象我将拥有一个抽象类字典和具体类:InvoiceTypeDictionary、PaymentTypeDictionary等(我可以将子类鉴别器设置为TypeId,就这样)。但是,有没有其他方法来避免必要的大量子类呢?我不确定值是什么
// InvoiceTypeMap : ClassMap<InvoiceType>
public InvoiceTypeMap()
{
Table("dictionaryTable");
Where("typeid=5");
Map(it => it.SomeProperty, "value");
}
// PaymentTypeMap : ClassMap<PaymentType>
public PaymentTypeMap()
{
Table("dictionaryTable");
Where("typeid=3");
Map(it => it.SomeOtherProperty, "value");
}
void SetInvoiceTypeToEntity(Invoice invoice, int invoicetypeid)
{
invoice.Invoicetype = session.Get<InvoiceType>(invoicetypeid);
// or when you only need the Reference without the actual object here
invoice.Invoicetype = session.Load<InvoiceType>(invoicetypeid);
}
//InvoiceTypeMap:ClassMap
公共发票类型映射()
{
表(“字典表”);
其中(“typeid=5”);
Map(it=>it.SomeProperty,“value”);
}
//PaymentTypeMap:ClassMap
公共支付类型映射()
{
表(“字典表”);
其中(“typeid=3”);
Map(it=>it.SomeOtherProperty,“value”);
}
作废SetInvoiceTypeToEntity(发票发票,int invoicetypeid)
{
invoice.Invoicetype=session.Get(invoicetypeid);
//或者只需要引用而不需要实际对象
invoice.Invoicetype=session.Load(invoicetypeid);
}