Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 按列表中的嵌套对象筛选_C#_Linq_Entity Framework Core - Fatal编程技术网

C# 按列表中的嵌套对象筛选

C# 按列表中的嵌套对象筛选,c#,linq,entity-framework-core,C#,Linq,Entity Framework Core,有人可以建议如何在LINQ中按嵌套对象进行过滤吗。 我有一个简单的1->多关系对象: public class WaybillReferences { public int WaybillID { get; set; } public string WaybillNo { get; set; } public DateTime? WaybillDate { get; set; } public string FromBCentre { get; set; }

有人可以建议如何在LINQ中按嵌套对象进行过滤吗。 我有一个简单的1->多关系对象:

public class WaybillReferences
{
    public int WaybillID { get; set; }
    public string WaybillNo { get; set; }
    public DateTime? WaybillDate { get; set; }
    public string FromBCentre { get; set; }
    public string ToBCentre { get; set; }
    public string FromCustomer { get; set; }
    public string ToCustomer { get; set; }
    public DateTime? PODDate { get; set; }
    public string Signee { get; set; }
    public int? BillingCustomerID { get; set; }
    public List<Order> orderReferences { get; set; }
}
现在,我的目标是为将在WaybillReference.WaybillNo和List.Id中搜索该#值的用户提供一个过滤器 这就是我尝试过的:

 var data = (from w in _context.Waybill
            join fromCust in _context.Customer on w.PickupCustId equals fromCust.Id
            join toCust in _context.Customer on w.DeliverCustId equals toCust.Id
            join fromBC in _context.Bcentre on fromCust.Pcode equals fromBC.Id
            join toBC in _context.Bcentre on toCust.Pcode equals toBC.Id
            select new WaybillReferences
            {
                WaybillID = w.Id,
                WaybillNo = w.CourierWbno,
                WaybillDate = w.Date,
                PODDate = w.Poddate,
                Signee = w.Signee,
                FromCustomer = fromCust.Name,
                ToCustomer = toCust.Name,
                FromBCentre = fromBC.Name,
                ToBCentre = toBC.Name,
                BillingCustomerID = w.BillCust,
                orderReferences = _context.Order.Where(y => y.WaybillId == w.Id).ToList()
            }).Where(x => BillCustomers.Contains(x.BillingCustomerID)
                   && (fromDate == null || x.WaybillDate >= fromDate)
                   && (toDate == null || x.WaybillDate <= toDate)
                   && (FilterBy.Equals("#") || x.WaybillNo.StartsWith(FilterBy))
                   && (FilterBy.Equals("#") || x.orderReferences.Any(x=> x.Id.StartsWith(FilterBy))) /*Error Here*/
           )
         .OrderBy(z => z.WaybillDate)
         .Take(300);

        return await data.ToListAsync();
var数据=(来自w in _context.Waybill
在w上的_context.Customer中加入fromCust。PickupCustId等于fromCust.Id
在w.DeliverCustId等于cust.Id时加入到_context.Customer中
在fromCust.Pcode等于fromBC.Id的_context.bcenter中加入fromBC
在toCust.Pcode等于toBC.Id上的_context.Bcentre中加入toBC
选择新的路标参考
{
WaybillID=w.Id,
WaybillNo=w.CourierWno,
WaybillDate=w.日期,
PODDate=w.PODDate,
签字人=w.签字人,
fromcuster=fromcuster.Name,
ToCustomer=toCust.Name,
FromBCentre=fromBC.Name,
ToBCentre=toBC.Name,
BillingCustomerID=w.BillCust,
orderReferences=\u context.Order.Where(y=>y.WaybillId==w.Id).ToList()
}).Where(x=>BillCustomers.Contains(x.BillingCustomerID)
&&(fromDate==null | | x.WaybillDate>=fromDate)
&&(toDate==null | | x.WaybillDate x.Id.StartsWith(FilterBy))/*此处出现错误*/
)
.OrderBy(z=>z.WaybillDate)
.采取(300);
返回wait data.toListSync();
感谢您的时间和帮助

编辑:我得到一个错误

InvalidOperationException:LINQ表达式“DbSet.Join(outer:DbSet,inner:w=>w.PickupCustId,outerKeySelector:c=>(可空)c.Id,innerKeySelector:(w,c)=>new transparentifier(outer=w,inner=c)).Join(outer:DbSet,inner:ti=>ti.outer.DeliverCustId,outerKeySelector:c0=>(可空)c0.Id,innerKeySelector:(ti,c0)=>新的透明标识符,客户>(Outer=ti,Inner=c0)).Join(Outer:DbSet,Inner:ti0=>ti0.Outer.Inner.Pcode,outerKeySelector:b=>b.Id,innerKeySelector:(ti0,b)=>新的透明标识符,客户>,Bcentre>(Outer=ti0,Inner=b)).Join(外部:DbSet,内部:ti1=>ti1.outer.inner.Pcode,outerKeySelector:b0=>b0.Id,innerKeySelector:(ti1,b0)=>新的透明标识符,Customer>,Bcentre>,Bcentre>(外部=ti1,内部=b0))。其中(ti2=>包含(ti2.outer.outer.outer.outer.outer.outer.outer.BillCust.BillCust)&&False|ti2.Outer.Outer.Outer.Outer.Date>=&uu from Date_1&&True&False|uu FilterBy_2==“ti2.Outer.Outer.Outer.Outer.CourierWbno!=null&&uu FilterBy_2!=null&&ti2.Outer.Outer.Outer.Outer.courierbno.StartsWith(u FilterBy| 2)和DbSet.Where(o=>o.billwayid==2.Outer.toll())(c=>False | | | | | | | c.Id!=null和&&&&| u FilterBy | u 2!=null和&&c.Id.StartsWith(| u FilterBy | u 2)))无法翻译。请以可以翻译的形式重写查询,或者通过插入对AsEnumerable()、asAsAsAsAsSyncEnumerable()、ToList()或ToListSync()的调用,显式切换到客户端计算。有关详细信息,请参阅


你的尝试有什么问题?你得到了什么错误?添加了错误。你的尝试有什么问题?你得到了什么错误?添加了错误。
 var data = (from w in _context.Waybill
            join fromCust in _context.Customer on w.PickupCustId equals fromCust.Id
            join toCust in _context.Customer on w.DeliverCustId equals toCust.Id
            join fromBC in _context.Bcentre on fromCust.Pcode equals fromBC.Id
            join toBC in _context.Bcentre on toCust.Pcode equals toBC.Id
            select new WaybillReferences
            {
                WaybillID = w.Id,
                WaybillNo = w.CourierWbno,
                WaybillDate = w.Date,
                PODDate = w.Poddate,
                Signee = w.Signee,
                FromCustomer = fromCust.Name,
                ToCustomer = toCust.Name,
                FromBCentre = fromBC.Name,
                ToBCentre = toBC.Name,
                BillingCustomerID = w.BillCust,
                orderReferences = _context.Order.Where(y => y.WaybillId == w.Id).ToList()
            }).Where(x => BillCustomers.Contains(x.BillingCustomerID)
                   && (fromDate == null || x.WaybillDate >= fromDate)
                   && (toDate == null || x.WaybillDate <= toDate)
                   && (FilterBy.Equals("#") || x.WaybillNo.StartsWith(FilterBy))
                   && (FilterBy.Equals("#") || x.orderReferences.Any(x=> x.Id.StartsWith(FilterBy))) /*Error Here*/
           )
         .OrderBy(z => z.WaybillDate)
         .Take(300);

        return await data.ToListAsync();