如何在 Fluent NHibernate 中创建此参考映射?
使用 Fluent NHibernate,我需要了解如何映射我的 Invoice 类。
public class Buyer
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual string TaxRegNo { get; set; }
// .... more properties....
}
public class Invoice
{
public virtual int Id { get; set; }
public virtual int IdBuyer { get; set; }
public virtual Buyer Buyer { get; set; }
// ....more properties
}
问题是我想在 Invoice 类中拥有:
- BuyerId - 只是一个用于参考和外键关系的整数 ID
- 几乎所有买家属性的副本(其会计凭证和属性在确认后无法更改) - 作为
我尝试这样做的 组件使用以下映射但它不起作用
public InvoiceMap()
{
Id(x => x.Id);
References(x => x.IdBuyer);
Component(x => x.Buyer, BuyerMap.WithColumnPrefix("buyer_"));
// ....more properties
}
Using Fluent NHibernate I need a clue how to map my Invoice class.
public class Buyer
{
public virtual int Id { get; set; }
public virtual string Name { get; set; }
public virtual string TaxRegNo { get; set; }
// .... more properties....
}
public class Invoice
{
public virtual int Id { get; set; }
public virtual int IdBuyer { get; set; }
public virtual Buyer Buyer { get; set; }
// ....more properties
}
The problem is that I want to have in Invoice class:
- BuyerId - just an integer ID for reference and foregin key relationship
- a copy of almost all buyer properties (its accounting document and properties cannot be changed after confirmation) - as component
I tried to this using following mapping but it doesn't work
public InvoiceMap()
{
Id(x => x.Id);
References(x => x.IdBuyer);
Component(x => x.Buyer, BuyerMap.WithColumnPrefix("buyer_"));
// ....more properties
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您通常不会同时映射外键和子对象。如果您确实映射两者,则在映射(或类似)中执行此操作:
然后您就不会在 SQL 语句中重复列名,这会导致参数数量不匹配的错误。
You would normally not map both the foreign key and the child object. If you do map both, then do this in the mapping (or similar):
Then you don't double up on the column name in SQL statements, which causes errors around mismatched numbers of parameters.