即使使用正确的 `splitOn`,Dapper 也不会填充实体?
Dapper doesn't fill entity, even with the right `splitOn`?
查看此简化 SQL 服务器查询:
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
)
如您所见,我正在 return 宁所有来自 Comments
和 Users
PLUS 一些 int
的列值。
好吧,我知道我不能 return 一个 int
值,我需要 return 一个实体。
这就是我创建这个虚拟 class 来保存 int
值的原因:
public class SqlInt
{
public int MyIntValue { get; set; }
}
如您所见,它是通用类型的一部分:
c.QueryAsync<Comment, User, SqlInt, CommentWithSenderAndUserId2>
所以基本上我会使用 Comment
、User
、SqlInt
并将其全部放入 CommentWithSenderAndUserId2
那么问题出在哪里呢?
我的虚拟 class 的 int 值永远不会被填充,它总是 0
(其他实体填充得很好)
I did read this post(就像我在 SP 中所做的那样)我应该添加一个分隔列,例如:
SELECT *,
SPLIT = '', <----------- Here
userid2 = @userid2
问题
我做错了什么以及我怎样才能填充 myInt 值?
好吧,我发现了我的愚蠢错误。
问题是我创建了一个实体来保存 int
值,对吗?
public class SqlInt
{
public int MyIntValue { get; set; }
}
属性 的名称是 MyIntValue
。如果是这样,我为什么要这样做:
SELECT *,
SPLIT = '',
userid2 = @userid2
而不是正确的方法:
SELECT *,
SPLIT = '',
MyIntValue = @userid2 <---- change is here
现在我确实看到了正确的值。
查看此简化 SQL 服务器查询:
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
)
如您所见,我正在 return 宁所有来自 Comments
和 Users
PLUS 一些 int
的列值。
好吧,我知道我不能 return 一个 int
值,我需要 return 一个实体。
这就是我创建这个虚拟 class 来保存 int
值的原因:
public class SqlInt
{
public int MyIntValue { get; set; }
}
如您所见,它是通用类型的一部分:
c.QueryAsync<Comment, User, SqlInt, CommentWithSenderAndUserId2>
所以基本上我会使用 Comment
、User
、SqlInt
并将其全部放入 CommentWithSenderAndUserId2
那么问题出在哪里呢?
我的虚拟 class 的 int 值永远不会被填充,它总是 0
(其他实体填充得很好)
I did read this post(就像我在 SP 中所做的那样)我应该添加一个分隔列,例如:
SELECT *,
SPLIT = '', <----------- Here
userid2 = @userid2
问题
我做错了什么以及我怎样才能填充 myInt 值?
好吧,我发现了我的愚蠢错误。
问题是我创建了一个实体来保存 int
值,对吗?
public class SqlInt
{
public int MyIntValue { get; set; }
}
属性 的名称是 MyIntValue
。如果是这样,我为什么要这样做:
SELECT *,
SPLIT = '',
userid2 = @userid2
而不是正确的方法:
SELECT *,
SPLIT = '',
MyIntValue = @userid2 <---- change is here
现在我确实看到了正确的值。