C# 使用Sqlite命令C将Foreach转换为Foreach#
我想做点像C# 使用Sqlite命令C将Foreach转换为Foreach#,c#,sqlite,C#,Sqlite,我想做点像 var records = db.Receipts.Where(re => re.Id.Equals(1)); foreach (var record in records) { //This is a relational table between the product table and the receipt table var proRec = db.ProductsReceipts.Where(re => re.ReceiptId.Eq
var records = db.Receipts.Where(re => re.Id.Equals(1));
foreach (var record in records)
{
//This is a relational table between the product table and the receipt table
var proRec = db.ProductsReceipts.Where(re => re.ReceiptId.Equals(record.Id));
foreach (var item in proRec)
{
//Something
}
}
这显示了一个错误:“当DataReader处于活动状态时,无法设置commandText”。我知道错误是什么意思,但我需要做一个循环。有什么想法吗
PD:im使用linq2db、nuget等我希望它看起来更像:
var records = db.Receipts.Include(r => r.ProductsReceipts).Where(re => re.Id.Equals(1));
foreach (var record in records)
{
foreach (var item in record.ProductsReceipts)
{
//Something
}
}
如果您要对连接到ProductsReceipts另一侧的产品执行某些操作,请同时加载:
var records = db.Receipts
.Include(r => r.ProductsReceipts).
.ThenInclude(pr => pr.Product)
.Where(re => re.Id.Equals(1));
使用
.ToList()
完成从第一个查询中获取数据。或者学习如何使用Join
首先只发送一个查询。boucle=loop en Anglais而不是Join,。包括(…)
导航属性。Ey@franzgleichman您的解决方案(query.ToList())简单有效,但是,在query.ToList()或执行Join查询之间,什么是最有效的操作?虽然这段代码是正确的,但没有解释为什么这更好。你刚刚完成了OP的工作,但没有解释他们为什么要这样做