Linq查询类型相等可以';我想不出来

Linq查询类型相等可以';我想不出来,linq,Linq,我在项目中使用Linq查询,无法修复查询之间的匿名类型错误。由于我无法为此创建特定的类,因此我决定在查询中转换为相同的类型,但我仍坚持使用此部分,无法使这两部分相等 &在另一个查询中 from x in db.table select new { property = 0 } from x in db.table select new { property = 0.000 } 我所需要的只是我的查询之间的并集,但我不能使这两部分相等 所以我可以使用这两个结果var query=part1.


我在项目中使用Linq查询,无法修复查询之间的匿名类型错误。由于我无法为此创建特定的类,因此我决定在查询中转换为相同的类型,但我仍坚持使用此部分,无法使这两部分相等

&在另一个查询中

from x in db.table
select new
{ property = 0 }
from x in db.table
select new
{ property = 0.000 }
我所需要的只是我的查询之间的并集,但我不能使这两部分相等 所以我可以使用这两个结果
var query=part1.union(part2)

编辑:我不确定我是否遗漏了声明为decimal的属性是否具有任何重要性

编辑:
找到了一个将十进制数转换为双精度的解决方案

&在另一个查询中

from x in db.table
select new
{ property = 0 }
from x in db.table
select new
{ property = 0.000 }

&然后我将值转换为第二部分

(from x in db.table
    from d in db.table2
    from c in db2.table
    select new {
    property = (x.property == 0) ?
    ((d.property == null) ? 0 :  double.parse(d.property.ToString()) ) :
    ((c.property == null) ? 0 : double.parse(c.property.ToString()) )}).distinct()
编辑
由于某种原因,该问题仍然存在,好像转换不起作用(匿名错误) 更新4.0

   var query_1 = (from d in ogcc.table
                     from adh in vclt.table
                     from a in vclt.table
                     where
                         stuff
                     select new
                     {
                         tx_int = "0" //the that keeps the anonymous error
                     }).Distinct();
    //union
    var query_2 = from d in prtf.table
                    from c in prtf.table
                    from a in vclt.table.Where(a => (c.num_credit == a.no_dos_adh || c.ref_cred == a.no_dos_adh)) //left join
                    where
                        stuff
                    select new
                    {
                        tx_int = prtf.Stored_Procedure(c.num_credit).ToString(),
                    };
更新+简化查询代码
其中只有一个保留了错误&我无法修复它

它是tx_int我试图将这两个属性都转换为字符串,但错误仍然存在

因为您正在检查,例如,
d.property==null
,我假设
d
是一个
可空的
,所以您想使用它的
属性,所以您使用的是
int
,而不是
int?

select new {
property = (x.property == 0) ?
((d.property == null) ? 0 :  d.property.Value ) :
((c.property == null) ? 0 : c.property.Value )}

你的核心没有编译。这不是一个正确的匿名类型声明,您缺少了
new
和大括号。我缩短了查询时间,太长了,无法使两部分相等。这解释不了多少。你会得到什么错误?当我使用联合时,它会抛出匿名错误thing@TheNewGuy:我注意到您更新了问题,但更新的代码显然不是您真正使用的代码。如果您不提供复制此问题的代码,我们将无法很容易地帮助您。我建议在你认为你知道事情是什么类型的地方进行显式强制转换,直到他们中的一个抱怨。我试过了,但联盟仍然没有任何其他想法?@StriplingWarrior或
d.property??0
等@TheNewGuy:它被称为“空合并运算符”。它说,“使用我前面的东西,除非它为空,在这种情况下,使用我后面的东西。”
var a=b??c与变量a=b!=无效的b:c