簡體   English   中英

新手on linq到sql lambda表達式后面的語句包括兩個

[英]Newbie on linq to sql lambda expression where statement after two includes

    var Query2 = from x in CoreDatabase.Set<tblPerson>()
                 .Include(a => a.tblApplicationInterface.Select(b => b.tblApplicationName)
                 .Where(c => c.AppplicationName == "MshHumanResources"))

                 select x;

我得到Include路徑表達式必須引用在類型上定義的導航屬性。 使用虛線路徑作為參考導航屬性,使用Select運算符作為集合導航屬性。 我只是想寫

這里有用的東西:

Select * 
From tblPerson a INNER JOIN tblApplicationInterface b 
on a.id = b.id
INNER Join tblApplicationName c
ON b.fkid=c.id
Where b.ApplicationName like 'MshHumanResources'

這不是Include工作方式。 您想要使用join

var Query2 = from a in CoreDatabase.Set<tblPerson>()
             join b in CoreDatabase.Set<tblApplicationInterface>() on a.id equlas b.id
             join c in CoreDatabase.Set<tblApplicationName>() on b.fkid equals c.id
             where c.AppplicationName == "MshHumanResources"
             select a;

這只是從A中選擇列 - 如果要從其他表中選擇列,請創建一個類來組合所需的字段或使用匿名類型。

嘗試這個:

var Query2 = CoreDatabase.Set<tblPerson>
                 .Include("tblApplicationInterface")
                 .Include("tblApplicationInterface.tblApplicationName")
                 .Where(x => x.ApplicationName == "MshHumanResources");

你可以直接說

var people = CoreDatabase.Set<tblPerson>().Where( p => 
p.tblApplicationInterface.tblApplicationName.ApplicationName == "MshHumanResources" );

如果我正確理解您的導航屬性。 這將選擇應用程序界面的應用程序名稱為MshHumanResources的人。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM