在 Fluent NHibernate 中映射人员和员工

发布于 2024-09-18 12:04:41 字数 401 浏览 3 评论 0原文

如何使用 Fluent NHibernate(实体、映射类等)映射以下查询,员工 ID 存储在标识符表中。人员表包含员工信息和非员工信息。

SELECT p.Id、p.FirstName、p.LastName

 FROM Person p  

UNION ALL

SELECT e.Id, e.FirstName, e.LastName 

  FROM Employee e 

INNER JOIN 标识符 i on (e.Id = i.value)

INNER JOIN 类型 t on (i.typeid = t.id and i.typeName = 'EmployeeId')

有人吗?

How can I map following queries using Fluent NHibernate (entity, mapping class etc..), the employee ids are stored in identifier tables. Person table contains employee information and non-employee information.

SELECT p.Id, p.FirstName, p.LastName

 FROM Person p  

UNION ALL

SELECT e.Id, e.FirstName, e.LastName 

  FROM Employee e 

INNER JOIN identifier i on (e.Id = i.value)

INNER JOIN type t on (i.typeid = t.id and i.typeName = 'EmployeeId')

Anyone?

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

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

发布评论

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

评论(1

向日葵 2024-09-25 12:04:41

您需要使用联合策略来映射您的子类。阅读 Fluent NHibernate wiki 的 子类化 部分,而不是调用 您可以在 ClassMap 中调用 UseUnionSubclassForInheritanceMapping 中的 DiscrimminateSubclassesOnColumn

您最终会得到一个基类的 ClassMap ,然后是每个子类的 SubclassMapClassMap 将在其构造函数中调用 UseUnionSubclassForInheritanceMapping

像这样的东西:

public class PersonMap : ClassMap<Person>
{
  public PersonMap()
  {
     // ... mappings ...
     UseUnionSubclassForInheritanceMapping();
  }
}

public class EmployeeMap : SubclassMap<Employee>
{
  public EmployeeMap()
  {
    // ... mappings ...
  }
}

You need to use a union strategy for mapping your subclasses. Have a read of the subclassing section of the Fluent NHibernate wiki, but instead of calling DiscriminateSubclassesOnColumn in your ClassMap you'd call UseUnionSubclassForInheritanceMapping.

What you'd end up with is a ClassMap for your base-class, then a SubclassMap for each of your subclasses; the ClassMap would have a call to UseUnionSubclassForInheritanceMapping in it's constructor.

Something like this:

public class PersonMap : ClassMap<Person>
{
  public PersonMap()
  {
     // ... mappings ...
     UseUnionSubclassForInheritanceMapping();
  }
}

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