2
望着這簡化 SQL Server查詢:即使使用正確的`splitOn`,Dapper不會填充實體嗎?
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
)
正如你可以看到我returnning所有列均來自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值?