有没有办法在流畅的 nhibernate 中使用指定过滤器的 Join 映射?

发布于 2024-10-11 19:29:48 字数 785 浏览 3 评论 0原文

我有一个场景,我想创建一个映射类,该类从两个表中提取数据。例如,我的两个表是 Persons 和 PersonAddresses。我希望生成的映射类将这两个合并在一起,如下所示:

public class PersonWithAddress
{
   public int ID { get; set; }
   // person fields ..

   // address fields
}

问题是每个人可以拥有多个地址,但只有一个地址被标记为他们的主要地址。这就是我想要拉入该实体的地址。所以我认为有一种方法可以在我的映射中使用 Join() 并在连接上指定一个过滤器,如下所示:

public PersonWithAddressMap()
{
   Table("People");
   Id(x => x.ID, "PersonID");

   Map(x => x.FirstName);
   // map all the person fields...

   Join("PersonAddresses", pa =>
   {
      pa.Optional();

      pa.Map(x => x.AddressLine1);
      // map all the other address fields

      // apply filtering
      pa.Where(x => x.IsPrimary == true);  // <-- does not exist
   });
}

有人知道如何做到这一点吗?

I have a scenario where I want to create map a class that pulls data from two table together. For example, my two tables are Persons and PersonAddresses. I want the resulting mapped class to merge these two together like this:

public class PersonWithAddress
{
   public int ID { get; set; }
   // person fields ..

   // address fields
}

The problem is each person can have more than one address, but only one address is marked as their primary address. That is the address I want to pull into this entity. So I thought there was a way to use Join() in my mapping and specify a filter on the join like this:

public PersonWithAddressMap()
{
   Table("People");
   Id(x => x.ID, "PersonID");

   Map(x => x.FirstName);
   // map all the person fields...

   Join("PersonAddresses", pa =>
   {
      pa.Optional();

      pa.Map(x => x.AddressLine1);
      // map all the other address fields

      // apply filtering
      pa.Where(x => x.IsPrimary == true);  // <-- does not exist
   });
}

Anyone know of a way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文