【问题标题】:Filter the results using n-hibernate via matching with another Db table通过匹配另一个 Db 表使用 n-hibernate 过滤结果
【发布时间】:2012-05-07 15:29:43
【问题描述】:

我已经编写了 Hbn & 代码来从 db 中获取用户。

有以下信息

用户名、姓名、电子邮件、电话

现在我们有了新的要求,新表已经创建了以下字段

表 1

  • userid -- 上面用户表的外键
  • 工作地点
  • WorkingStatusId

表 2

  • WorkingStatusId
  • 工作状态

过滤条件是工作地点和工作状态

我无法更改我现有的代码。

要么我必须编写新的 hbn 文件并编写代码

或者我应该使用之前创建的 hbn 获取数据并过滤它

请向我推荐使用 linq 等的代码(如果可能的话)

【问题讨论】:

    标签: nhibernate linq-to-nhibernate nhibernate-criteria


    【解决方案1】:

    向用户添加Workplaces 或其他任何内容的集合并将其映射,这样就很容易查询

    from u in session.Query<User>()
    from w in u.Workplaces
    where ...
    select u;
    

    或在映射 Workplaces 后使用相关子查询进行过滤

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-12-12
      • 2016-10-11
      • 1970-01-01
      • 1970-01-01
      • 2020-12-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多