I have a base class which holds two sub classes, and the base class has no extra properties. I want to use dapper multiple mapping to map the data to sub classes directly. But in split-on property it gives and exception saying
"When using the
multi-mapping APIs
ensure you set thesplitOn
param
if you have keys other than Id```
and i am unable to split in the first column itself.
public class User
{
public int UserId {get; set;}
public string UserName {get; set;}
}
public class Business
{
public int BusinessId {get; set;}
public string BusinessName {get; set;}
}
public class UserAndBusiness
{
public User UserDetails{get; set;}
public Business BusinessDetails{get; set;}
}
var userDetails = await dbConnection.QueryAsync<UserAndBusiness,
User,Business,UserAndBusiness>(@"
select User_Id UserId,User_Name UserName,Business_Id BusinessId,
Business_Name BusinessName from Users u join Business b on u.User_Id=b.User_Id",
map:(ub,u,b)=>
{
ub.UserDetails=u;
ub.BusinessDetails=b;
return ub;
},
splitOn:"UserId,BusinessId"
);
Here i want to split the result right from beginning to assign data to sub classes