我試圖替換我的大,醜陋的查詢;雖然醜它的工作原理是期望: -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