[英]How to use Npoco FetchOneToMany?
I am trying to use Npoco but running into some problems with FetchOneToMany 我试图使用Npoco但遇到了FetchOneToMany的一些问题
I have a sql statement that joins 2 tables together and I output all the columns. 我有一个连接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");
I am passing 4 parameters in my real query. 我在我的真实查询中传递了4个参数。 I get a result back and TableBs property
is filled and looks good. 我得到一个结果,并且TableBs property
被填充并且看起来很好。 However EffectiveDate is not filled for some reason and is the default C# time. 但是,由于某种原因,EffectiveDate未填充,并且是默认的C#时间。
What am I missing? 我错过了什么?
Edit 编辑
This is what I have as my query 这就是我的查询
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");
This is how it should work. 这是应该如何工作的。
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))
You must ensure your columns are selected in the same order that the generic parameters are listed. 您必须确保以与列出通用参数相同的顺序选择列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.