【问题标题】:How to return multiple result in nhibernate using c#如何使用c#在nhibernate中返回多个结果
【发布时间】:2018-03-15 01:36:20
【问题描述】:

我有一个存储过程,它使用 c# 在 Nhibernate 中返回多个结果集,下面是 c# 代码,但我无法返回哪种类型,因为我有 3 个类型为 lure、bait 和 fly 的结果集。那么对此有什么想法吗?或者我需要更改代码。

public somereturn GetData() {
    var query = _session.CreateSQLQuery("exec GetTopProducingStats 
      @userId=:userId");
    query.SetParameter("userId", userId);
    var result = _session.CreateMultiQuery()
        .Add(query.AddEntity(typeof(Lure)))
        .Add(_session.CreateSQLQuery("").AddEntity(typeof(Bait)))
        .Add(_session.CreateSQLQuery("").AddEntity(typeof(Fly)))
        .List();
}

【问题讨论】:

  • 根据调试器,result 是什么类型?列出?
  • 根据调试器结果是数组的 Ilist 类型(result[0] 是 lure 类型,result[1] 是 Bait 类型......等等)所以总共 3 个结果..

标签: c# .net fluent-nhibernate


【解决方案1】:

根据您对我的评论的回答,您可以将 somereturn 设为 IList

public IList GetData() {
    var query = _session.CreateSQLQuery("exec GetTopProducingStats 
      @userId=:userId");
    query.SetParameter("userId", userId);
    var result = _session.CreateMultiQuery()
        .Add(query.AddEntity(typeof(Lure)))
        .Add(_session.CreateSQLQuery("").AddEntity(typeof(Bait)))
        .Add(_session.CreateSQLQuery("").AddEntity(typeof(Fly)))
        .List();
    return result;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-02
    • 2015-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多