如何在 Fluent NHibernate 中创建此参考映射?

发布于 2024-08-13 01:37:17 字数 836 浏览 2 评论 0原文

使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゞ花落谁相伴 2024-08-20 01:37:17

您通常不会同时映射外键和子对象。如果您确实映射两者,则在映射(或类似)中执行此操作:

References(x => x.Buyer);
Map(x => x.IdBuyer).Column("BuyerId").Not.Insert().Not.Update();

然后您就不会在 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):

References(x => x.Buyer);
Map(x => x.IdBuyer).Column("BuyerId").Not.Insert().Not.Update();

Then you don't double up on the column name in SQL statements, which causes errors around mismatched numbers of parameters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文