Dapper
Dapper copied to clipboard
One to One mapping and join two condition, how to set splitOn
my sql is like this
string sql = SELECT * FROM B JOIN A ON B.ColumnD = A.ColumnD AND B.ColumnE = A.ColumnE
class TestA
{
public string ColumnD { get; set; }
public string ColumnE { get; set; }
public string ColumnF { get; set; }
public string ColumnG { get; set; }
}
class TestB
{
public string ColumnA { get; set; }
public string ColumnB { get; set; }
public string ColumnC { get; set; }
public string ColumnD { get; set; }
public string ColumnE { get; set; }
public TestA Item { get; set; }
}
this is one to one mapping result
#IEnumerable<TestB> GetTestB()
{
return Connection.Query<TestB, TestA, TestB>(
sql,
(b, a) =>
{
b.Item = a;
return b;
},
splitOn: "ColumnD,ColumnE");
}
but the result TestA always NULL splitOn setting wrong?
The problem you're seeing here is almost certainly related to the duplicate columns of the same name. Can you show what a column list from that query looks like? The order coming back from the database is what matters, Dapper will look for the first ColumnD and the first ColumnE after that.