我有两个实体框架查询,每个查询返回两列,并且我想出于绑定原因连接或连接两个查询的结果,
我已经尝试过Concat
方法,但它抛出:
无法转换类型的对象
'System.Data.Entity.Infrastructure.DbQuery`1[VB$AnonymousType_3`2[System.String,System.String]]'
to type
'System.Collections.Generic.IEnumerable`1[VB$AnonymousType_2`2[System.String,System.String]]
'.
这是我的代码:
Dim r = (From PropertyDefinitions In econtext.PropertyDefinitions Join ProductPropertyValues In
econtext.ProductPropertyValues On ProductPropertyValues.ProductPropDefID Equals PropertyDefinitions.PropertyDefID
Join AdProductDefValues In econtext.AdProductDefValues
On AdProductDefValues.PropValueID Equals ProductPropertyValues.ProductPropValueID
Where AdProductDefValues.AdID = AdID
Select PropertyDefinitions.PropertyDefName2, AdProductDefValues.DefValue2).Concat(From AdCustomProperties In econtext.AdCustomProperties
Where AdCustomProperties.AdID = AdID
Select AdCustomProperties.PropertyTitle2, AdCustomProperties.PropertyValue2)
GridProperties.DataSource = r.ToArray()
GridProperties.DataBind()
有什么想法可以结合两个查询的结果吗?
枚举不能串联,因为它们是不同的匿名类型,并且具有不同的属性名称。
一种解决方案是使类型匹配,例如你可以替换这部分:
Select PropertyDefinitions.PropertyDefName2, AdProductDefValues.DefValue2
有了这个
Select New With { .Name = PropertyDefinitions.PropertyDefName2, _
.Value = AdProductDefValues.DefValue2 }
同样:
Select New With { .Name = AdCustomProperties.PropertyTitle2, _
.Value = AdCustomProperties.PropertyValue2 }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)