匿名类型名称冲突

Cha*_*sch 17 c# linq anonymous-types

返回匿名类型的linq查询在执行时会引发以下错误.

The type '<>f__AnonymousType9<Name,Value>' exists in both    
'Customer.CustomerWeb.Presentation.dll' and 'Customer.CustomerContext.dll'
Run Code Online (Sandbox Code Playgroud)

使用JetBrains dotPeek我能够发现有2个编译器生成的类发生冲突.

Customer.CustomerContext.dll

 internal sealed class <>f__AnonymousType9<<PayrollSiteID>j__TPar, <IsActive>j__TPar>
Run Code Online (Sandbox Code Playgroud)

Customer.CustomerWeb.Presentation.dll

 internal sealed class <>f__AnonymousType9<<Name>j__TPar, <Value>j__TPar>
Run Code Online (Sandbox Code Playgroud)

两个生成的类都在根目录中namespace.有什么办法可以Anonymous Type classes指向每个程序集上的特定命名空间吗?简单的解决方法是向其中一个匿名查询添加第三个变量,但这更像是一个黑客攻击.

Bar*_*est 1

我认为您想要类似以下内容的内容,在名称空间内添加 using 语句,以使其在名称解析中具有优先权:

using Customer.CustomerContext;
namespace yourNameSpace
{
    using Customer.CustomerWeb.Presentation; //Where f__AnonymousType9<Name,Value> exists
}
Run Code Online (Sandbox Code Playgroud)