我正在尝试使用Npoco,但遇到了FetchOneToMany的一些问题
我有一个连接2个表的sql语句,我输出所有列。
[TableName("TableA")]
[PrimaryKey("Id")]
public class TableA
{
public int Id { get; set; }
public DateTime EffectiveDate { get; set; }
public IList<TableB> TableBs { get; set; }
}
[TableName("TableB")]
[PrimaryKey("TableBId")]
public class TableB
{
public int TableBId { get; set; }
public int SomeNumber { get; set; }
public int Id { get; set; } // TableA id
}
Func<TableA, object> func1 = (x) => x.Id;
Func<TableB, object> func2 = (x) => x.Id;
var test = RelationExtensions.FetchOneToMany<AdminFeeBandGroup, AdminFeeBand>(unitOfWork.Db, func1,func2,sql, 1,1,"10-18-2012","10-22-2012");
我在实际查询中传递了4个参数。我得到一个结果,TableBs property
已填满,看起来不错。但是,由于某种原因,EffectiveDate未被填充,并且是默认的C#时间。
我错过了什么?
修改
这就是我的查询
SELECT TableA.Id, TableA.EffectiveDate, TableB.TableBId, TableB.SomeNumber
FROM TableA INNER JOIN
TableB ON TableA.Id = TableB.Id
WHERE (TableA.EffectiveDate = @0)
Func<TableA, object> func1 = (x) => x.Id;
Func<TableB, object> func2 = (x) => x.Id;
var test = RelationExtensions.FetchOneToMany<AdminFeeBandGroup, AdminFeeBand>(unitOfWork.Db, func1,func2,sql, "10-18-2012");
答案 0 :(得分:1)
这是应该如何运作的。
var sql = "select a.*, b.* from tablea a
inner join tableb b on a.id = b.id
where EffectiveDate = @0"
List<TableA> results =
db.FetchOneToMany<TableA,TableB>(x=>x.Id, sql, new DateTime(2012,10,18))
您必须确保按照列出通用参数的顺序选择列。