当我尝试使用MVC代码进行左外连接时,我得到了这个错误:
join子句中某个表达式的类型不正确。 调用'GroupJoin'时类型推断失败。
我需要帮助才能理解join子句错误的原因。这是代码:
return (from t in context.Tenders
join c in context.Contacts on t.Contacts equals c.Tenders into leftOuter
from subpet in leftOuter.DefaultIfEmpty()
orderby t.id
where (c.Email == currentUserProfile.Email || c.UserProfileId == currentUserProfile.Id || t.UserProfileId == currentUserProfile.Id) && t.EndDate > now
&& t.IsClosed == false
&& t.IsCancel == false
select t).Union(
from t in context.Tenders
where t.EndDate > now
&& t.IsClosed == false
&& t.IsCancel == false
&& t.PrivacyLevelId == 1
select t).Count();
Fluent API:
// Many to many Tender => Contact
modelBuilder.Entity<Tender>()
.HasMany(c => c.Contacts)
.WithMany(t => t.Tenders)
.Map(m => m.MapLeftKey("TenderId")
.MapRightKey("ContactId")
.ToTable("ContactTender"));