我试图替换我的大,丑陋的查询;虽然丑它的工作原理是期望: -LINQ查询与包含语句中的Where子句
using (var ctx = new Data.Model.xxxTrackingEntities())
{
var result = ctx.Offenders
.Join(ctx.Fees, o => o.OffenderId, f => f.OffenderId,
(o, f) => new { Offenders = o, Fees = f })
.Join(ctx.ViolationOffenders, o => o.Fees.ViolationId, vo => vo.ViolationId,
(o, vo) => new { Offenders = o, ViolationOffenders = vo })
.Join(ctx.Violations, v => v.ViolationOffenders.ViolationId, vo => vo.ViolationId,
(v, vo) => new { Violations = v, ViolationOffenders = vo })
.Where(o => o.Violations.Offenders.Offenders.YouthNumber != "")
.ToList();
gvwData.DataSource = result;
}
具有以下LINQ查询: -
var result = ctx.Offenders
.Include(o => o.Fees.Where(f => f.Amount != null))
.Include(o => o.ViolationOffenders)
.Include(o => o.ViolationOffenders.Select(of => of.Violation))
.Where(o => o.YouthNumber != "" && o.FirstName != "")
.ToList();
我吹起来的查询二号线......一旦我添加了WHERE子句。 .. o => o.Fees.Where(f=> f.Amount != null)
该错误消息我得到...
The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.
此外,我试图写M个Ÿ查询为: -
var result = ctx.Offenders
.Include(o => o.Fees)
.Include(o => o.ViolationOffenders)
.Include(o => o.ViolationOffenders.Select(of => of.Violation))
.Where(o => o.YouthNumber != "" && o.FirstName != "" && o.Fees.Where(f=> f.Amount != null))
.ToList();
但后来我得到以下错误: -
Operator '&&' cannot be applied to operands of type 'bool' and 'System.Collections.Generic.IEnumerable
我知道这个概念是对的,但我需要的语法帮助。
什么'o.Fees.Where(F => f.Amount!= NULL)'应该是。你对它有什么期望? –
我希望我的结果变量中的1个项目每个Fee项目 – Philo