私はこれを持っています:
public class object_a
{
public int ta_Id { get; set; }
public string ta_Label { get; set; }
public IEnumerable<table_c> SomeName { get; set; }
}
public class table_b
{
public int Id {get;set;}
public int SomeId {get;set;}
public int FK_A {get;set;}
}
public class table_c
{
public int Id {get;set;}
public int Max {get;set;}
public string Label {get;set;}
public int FK_A {get;set;}
}
object_a
Dapper を使用して、任意の数の子オブジェクトのリストを取得しますtable_c
using (System.Data.SqlClient.SqlConnection sqlConnection = new System.Data.SqlClient.SqlConnection(_con))
{
sqlConnection.Open();
var sql = string.Format(
@"
select ta.Id as ta_Id, ta.Label as ta_label, splitLimit = '', tc.Id, tc.Max, tc.Label
from table_a as ta
left join table_b as tb
on tb.FK_A = ta.Id
left join table_c as tc
on tc.FK_A = ta.Id
where tb.SomeId = SomeInt);
var items = sqlConnection.Query<object_a, IEnumerable<table_c>, object_a>(sql, (a, c) => { a.c = table_c; return a; }, splitOn: "splitLimit");
return items;
}
コントローラーから Dapper コードを呼び出すと、次のエラーが発生します。
より適切な実体化を可能にするには、パラメーターなしのデフォルト コンストラクターが必要です。
私もこれを試しました:
var items = sqlConnection.Query<object_a,IEnumerable<table_c>, object_a>(sql, (a, c) =>
{
if (c!= null)
{
a.SomeName = c;
}
return a;
}, splitOn: "splitLimit");
と関係があるのではないかと思いますが、IEnumerable<table_c>
ここで何が間違っているのかわかりません。SOが提案する関連する質問を読みましたが、「わかりません」。
何が間違っているのか、正しいコードは何かを知りたいです。ありがとう!