c# - linq连接错误

标签 c# linq entity-framework join

我有这个 linq 查询:

var segreterie = from s in db.USR_Utenti join h in db.USR_Accounts
                     on new {s.ID, settings.GruppoSegreteria} 
                     equals new {h.USR_UtentiReference,h.ID_Gruppo} select s;

有这个问题:

The type of one of the expressions in the join clause is incorrect.  Type inference failed in the call to 'Join'.   

我该如何解决?

最佳答案

这两种类型应该相同——这意味着它们需要与您使用匿名类型相同的属性名称。试试这个:

var segreterie = from s in db.USR_Utenti join h in db.USR_Accounts
                 on new {s.ID, Groups = settings.GruppoSegreteria} 
                 equals new {ID = h.USR_UtentiReference, Groups = h.ID_Gruppo}
                 select s;

假设 s.IDh.USR_UtentiReference 具有相同的类型,并且 settings.GruppoSegreteriah.ID_Gruppo 照样做。

关于c# - linq连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2478919/

相关文章:

c# - 提高性能但需要维护的计算字段 (EF)

c# - 通过使用带有 async/await 的 Linq 延迟执行而感到震惊

c# - 如何使用 LINQ to SQL 设置整个对象?

c# - 在 SQL 数据库和 EF6 中保存标志枚举。这可能吗?

.net - 如何在代码优先 Entity Framework 中使用 View

c# - 使用 Entity Framework 查找

c# - 通过反射将对象附加到 IEnumerable<>

c# - 当 JsonConstructor 参数名称与 JSON 不匹配时如何抛出异常?

c# - 自定义xml反序列化陷入死循环

c# - IQueryable 到 string[] 数组?