Reputation: 148524
Looking at this simplified SQL Server query :
set @userid2=...
SELECT *,
SPLIT = '',
userid2 = @userid2
FROM Comments c
JOIN Users u
ON ...
I'm using this partially working code to execute the 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
)
As you can see I'm returnning all columns both from Comments
and Users
PLUS some int
value.
Well I know that I can't return an int
value just like that , I need to return an entity .
That's why I've created this dummy class to hold an int
value :
public class SqlInt
{
public int MyIntValue { get; set; }
}
And as you can see , it is part of the generic types :
c.QueryAsync<Comment, User, SqlInt, CommentWithSenderAndUserId2>
So basically I'm taking a Comment
, User
, SqlInt
and put it all in CommentWithSenderAndUserId2
So where is the problem ?
The int value of my dummy class never gets filled and it's always 0
( other entities filled just fine)
I did read this post ( as I did in my SP) that I should add a splitter column such as :
SELECT *,
SPLIT = '', <----------- Here
userid2 = @userid2
Question
What am I doing wrong and How can I get myInt value filled ?
Upvotes: 2
Views: 547
Reputation: 148524
Well, I found my silly mistake.
Problem was that I've created an entity to hold an int
value, right ?
public class SqlInt
{
public int MyIntValue { get; set; }
}
The name of the property is MyIntValue
. If so , Why did I do this :
SELECT *,
SPLIT = '',
userid2 = @userid2
Rather than the right approach :
SELECT *,
SPLIT = '',
MyIntValue = @userid2 <---- change is here
Now I do see that right value.
Upvotes: 1