我有以下類別:LINQ聯接查詢與ICollection的
public partial class Person : ModificationEntity
{
public Person()
{
this.PersonCompanies = new List<PersonCompany>();
}
public System.Guid PersonId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public virtual ICollection<PersonCompany> PersonCompanies { get; set; }
}
public partial class PersonCompany : ModificationEntity
{
public System.Guid PersonCompanyId { get; set; }
public System.Guid PersonId { get; set; }
public System.Guid CompanyId { get; set; }
public virtual Company Company { get; set; }
public virtual Person Person { get; set; }
}
我需要查詢給出companyids(名單lstCompanyIds)的列表中的所有用戶。
所以我把所有的PersonCompanyId與下面的查詢:
var qpc = (from c in lstCompanyIds
join u in personCompanyService.GetPersonCompanies()
on c equals u.CompanyId
select u.PersonCompanyId).AsQueryable();
與此查詢,我想要得到的用戶:
var query = from q in GetUsers()
join q2 in qpc
on q.PersonCompanies.Select(y => y.PersonCompanyId) equals q2
select q;
但是,這給出了一個編譯錯誤「之類的連接子句中的其中一個表達式不正確。在對「加入」的調用中,類型推斷失敗。 很明顯,因爲我試圖做一個選擇收集personcompanies。但是,我如何正確地做到這一點? (包含不工作,因爲我有兩個集合來比較...)
您是否檢查了此問題和解決方案? :http://stackoverflow.com/questions/19184019/the-type-of-one-of-the-expressions-in-the-join-clause-is-incorrect-in-entity-fra – 2015-04-02 09:25:34
是'PersonCompanyId'和相同類型的「q2」(* System.Guid *)? – Loetn 2015-04-02 09:27:04
@BurakKarakuş是的,但無法弄清楚這是如何解決我的問題。 – JurgenStillaert 2015-04-02 09:28:13