【发布时间】:2017-02-11 18:29:27
【问题描述】:
看看这个简化的 SQL Server 查询:
set @userid2=...
SELECT *,
SPLIT = '',
userid2 = @userid2
FROM Comments c
JOIN Users u
ON ...
我正在使用这个部分工作代码来执行 SP:
await c.QueryAsync<Comment, User, SqlInt, CommentWithSenderAndUserId2>(@"insertCommentByImageId",
(message1, user, myint) => new CommentWithSenderAndUserId2
{
User = user,
Comment = message1,
UserId2 = myint.MyIntValue
},
new {imageid = imageId, userid1 = userid1, comment = comment}, //parms
splitOn: "UserID,split", //splits
commandType: CommandType.StoredProcedure //command type
)
如您所见,我将返回来自 Comments 和 Users PLUS 的所有列以及一些 int 值。
我知道我不能像这样返回 int 值,我需要返回一个实体。
这就是为什么我创建了这个虚拟类来保存int 值:
public class SqlInt
{
public int MyIntValue { get; set; }
}
如您所见,它是泛型类型的一部分:
c.QueryAsync<Comment, User, SqlInt, CommentWithSenderAndUserId2>
所以基本上我会使用Comment、User、SqlInt 并将其全部放入CommentWithSenderAndUserId2
那么问题出在哪里?
我的虚拟类的 int 值永远不会被填充,它总是 0(其他实体填充得很好)
I did read this post(就像我在我的 SP 中所做的那样)我应该添加一个拆分列,例如:
SELECT *,
SPLIT = '', <----------- Here
userid2 = @userid2
问题
我做错了什么,如何填充 myInt 值?
【问题讨论】:
标签: c# sql-server dapper .net-4.6