【问题标题】:Ambiguous reference between two namespaces两个命名空间之间的模糊引用
【发布时间】:2014-10-03 07:23:05
【问题描述】:

我收到以下错误

错误 36 'SLICDataContext' 是一个不明确的引用 'SLIC_DataAccess.SLICDataContext' 和 'SLIC_DataAccess.Generic.SLICDataContext' CreateRequest.aspx.cs 48 36 C:...

代码:

int num = (
    from x in (new SLICDataContext()).ClientsToPriorities
        where x.PriorityID == Convert.ToInt32(this.drpPriority.SelectedValue)
        where x.ClientID == this.GetClientID
    select x.ClientToPriorityID).Single<int>();
return num;

我正在使用的命名空间

using SLIC_DataAccess.Generic;
using SLIC_DataAccess;

如何更具体地引用我的代码中的命名空间来解决这个问题?

【问题讨论】:

  • 看起来你有两个同名的类,但在两个不同的命名空间中。关于您的命名空间名称,我想知道是否存在更高级别的问题。它是自动生成的代码吗?如果是,生成是否​​正确设置?你不能重命名这两个类中的任何一个吗?

标签: asp.net .net linq


【解决方案1】:

您需要使用适用的命名空间完全限定您的代码中的类。

根据实现,它将是以下之一:

from x in (new SLIC_DataAccess.Generic.SLICDataContext()).ClientsToPriorities

 from x in (new SLIC_DataAccess.SLICDataContext()).ClientsToPriorities

另一种选择是使用别名,如下所示:

using SLIC_DA_Generics = SLIC_DataAccess.Generic;
using SLIC_DA = SLIC_DataAccess;

适当的用法如下:

from x in (new SLIC_DA_Generics.SLICDataContext()).ClientsToPriorities

from x in (new SLIC_DA.SLICDataContext()).ClientsToPriorities

【讨论】:

    【解决方案2】:

    您可以明确说出您希望使用哪个命名空间,例如:

    from x in (new SLIC_DataAccess.Generic.SLICDataContext()).ClientsToPriorities
    

    【讨论】:

      猜你喜欢
      • 2023-03-10
      • 2023-03-12
      • 1970-01-01
      • 2012-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-25
      相关资源
      最近更新 更多