我正尝试使用ServiceStack.OrmLite使用来自多个不同源表的数据来选择POCO。我遵循C# 7 Tuples下显示的常规语法,但是返回一个具体的POCO而不是一个元组。我正在解析SqlExpression
。
var exp = Db.From<TransactionProduct>()
.Join<Transaction>()
.Join<Product>()
.Join<Transaction, Device>()
.Select<Transaction, Device>((t, d) =>
new BottleBox
{
Location = d.Name,
Notes = t.Note,
Timestamp = t.TimeStamp
});
错误是:
Error CodeInvalidOperationException
Messagevariable 't' of type 'BMS.ServiceModel.Transactions.Transaction' referenced from scope '', but it is not definedStack
在Select
“ exp”定义末尾的SqlExpression
语句中似乎存在一些错误,但是我一生无法弄清楚发生了什么...
答案 0 :(得分:1)
自定义选择投影应使用匿名类型:
.Select<Transaction, Device>((t, d) =>
new {
Location = d.Name,
Timestamp = t.TimeStamp
});
在将结果集选择为特定的具体类型时,您将使用POCO:
var results = db.Select<BottleBox>(q);