【问题标题】:ORMLite SqlList with TuplesORMLite SqlList 与元组
【发布时间】:2018-09-11 09:46:24
【问题描述】:

我在使用 ORMLite 从自定义 SQL 查询中选择对象的 Tuple 时遇到一些问题。

我有以下代码:

var query = "select definition.*, timeslot.*, type.* from <blah blah>";
var defs = dbConnection.SqlList<Tuple<Definition, Timeslot, Type>>(query, new
                {
                    /* query parameters */
                });

查询本身没问题(我在 SQL Management Studio 中测试过)。

上面的代码只为Tuple 的第一项设置属性,其他的保持默认状态。

我已经单独选择了每个对象,结果是正确的(所以我猜在转换为POCO 的过程中没有问题)。

如果我使用 Select&lt;Tuple&lt;Definition, Timeslot, Type&gt;&gt; 而不是 SqlList,也会出现同样的情况。

我无法尝试使用 MultiSelect,因为它似乎不带字符串。

以这种方式选择Tuple 的正确方法是什么?

我在C#工作。

提前致谢!

【问题讨论】:

    标签: c# ormlite-servicestack


    【解决方案1】:

    SelectMulti 似乎就是您要在这里寻找的东西。

    来自the documentation在连接的表中选择多个列 标题下:

    // Note: I'm making an assumption on your query here.
    // Build the `q` object however it needs to be.
    
    var q = db.From<Definition>()
              .Join<Definition, Timeslot>()
              .Join<Definition, Type>();
    
    var results = db.SelectMulti<Definition, Timeslot, Type>(q);
    
    foreach (var tuple in results)
    {
        var definition = tuple.Item1;
        var timeslot = tuple.Item2;
        var type = tuple.Item3;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多