C# 具有多个连接的复杂LINQ查询语法错误
我有一个连接两个列表并创建一个新对象列表的查询,我想用一个新的连接来增强这一点,但到目前为止,我尝试的一切似乎都不起作用 名单如下:C# 具有多个连接的复杂LINQ查询语法错误,c#,linq,asp.net-mvc-4,join,C#,Linq,Asp.net Mvc 4,Join,我有一个连接两个列表并创建一个新对象列表的查询,我想用一个新的连接来增强这一点,但到目前为止,我尝试的一切似乎都不起作用 名单如下: IList<Content> result IList<Content> resultDefault Resharper给出了一个“无法推断方法的类型参数”。很遗憾,我不能复制粘贴那个 正确的联接语法是什么?创建组时,会丢失以前的引用。在这一点上,你不再有x,这都是关于g和z的,所以我的查询是不可能的?我不会这么说。请看一下这里的示例:。
IList<Content> result
IList<Content> resultDefault
Resharper给出了一个“无法推断方法的类型参数”。很遗憾,我不能复制粘贴那个
正确的联接语法是什么?创建组时,会丢失以前的引用。在这一点上,你不再有
x
,这都是关于g
和z
的,所以我的查询是不可能的?我不会这么说。请看一下这里的示例:。分组时可以创建自定义对象。
IEnumerable<ContentItem> joined = from x in resultDefault
join y in result on new { x.ResourceKey, x.ResourceType, x.Application } equals new { y.ResourceKey, y.ResourceType, y.Application } into g
from o in g.DefaultIfEmpty(new Content()
{
Id = 0,
CultureCode = cultureCode,
ResourceKey = x.ResourceKey,
ResourceType = x.ResourceType,
ResourceValue = String.Empty
})
where
(
resourcesJoin == ResourcesJoin.All ||
(resourcesJoin == ResourcesJoin.Translated && o.ResourceValue != String.Empty) ||
(resourcesJoin == ResourcesJoin.NotTranslated && o.ResourceValue == String.Empty)
)
&&
(
string.IsNullOrEmpty(searchString) ||
(
x.ResourceKey.ContainsIgnoreCase(searchString) ||
x.ResourceValue.ContainsIgnoreCase(searchString) ||
o.ResourceValue.ContainsIgnoreCase(searchString)
)
)
select new ContentItem(o, x);
IList<DifferentContent> resultCollection;
IEnumerable<ContentItem> joined = from x in resultDefault
join y in result on new { x.ResourceKey, x.ResourceType, x.Application } equals new { y.ResourceKey, y.ResourceType, y.Application } into g
from o in g.DefaultIfEmpty(new Content()
{
Id = 0,
CultureCode = cultureCode,
ResourceKey = x.ResourceKey,
ResourceType = x.ResourceType,
ResourceValue = String.Empty
})
join z in resultCollection on new { x.ResourceKey, x.ResourceType, x.Application, x.CultureCode } equals new { z.ResourceKey, z.ResourceType, z.Application, defaultCultureCode } into m
from s in m.DefaultIfEmpty(new DifferentContent()
{
Id = 0,
CultureCode = defaultCultureCode,
ResourceKey = x.ResourceKey,
ResourceType = x.ResourceType,
ResourceValue = string.Empty
})
where
(
resourcesJoin == ResourcesJoin.All ||
(resourcesJoin == ResourcesJoin.Translated && o.ResourceValue != String.Empty) ||
(resourcesJoin == ResourcesJoin.NotTranslated && o.ResourceValue == String.Empty)
)
&&
(
string.IsNullOrEmpty(searchString) ||
(
x.ResourceKey.ContainsIgnoreCase(searchString) ||
x.ResourceValue.ContainsIgnoreCase(searchString) ||
o.ResourceValue.ContainsIgnoreCase(searchString)
)
)
select new ContentItem(o, x, s);
The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'GroupJoin'.