ToDictionary错误"无法将带[]的索引应用于类型'方法组的表达式'"

时间:2014-03-20 10:42:08

标签: c# asp.net asp.net-mvc entity-framework

我的asp.net mvc web应用程序中有以下代码: -

 public void syncWithEX()
 {
     var EXresource = entities.Resources.Select(g => new
     {
         EXID = g.RESOURCEID,
         CurrentEXSiteID = g.ResourceLocation.SITEID
     }).ToDictionary(a => a.EXID, a => a.CurrentEXSiteID);
     var technology = ITSys.Technologies.Select(g => new
     {
          ID = g.TechnologyID,
          EXID = g.EXID
     }).ToDictionary(a => a.ID, a => a.EXID);

     var server = ITSys.ITSYSServers.Where(a => !a.Technology.IsDeleted && a.Technology.IsCompleted);
     foreach (var s in server)
     {
          long? EXid = technology[s.ITSYSServerID];
          if (EXresource.ContainsKey[EXid.Value] )
          {
              long? CurrentEXsiteid = EXresource[EXid.Value];
              if (CurrentEXsiteid != s.EXSiteID)
              {
                   s.EXSiteID = CurrentEXsiteid.Value;
                   ITSys.Entry(s).State = EntityState.Modified;
              }
          }
     }

但我收到以下错误:

  

无法将[]索引应用于“方法组”

类型的表达式

以下代码:

if (EXresource.ContainsKey[EXid.Value] )

1 个答案:

答案 0 :(得分:4)

更改为:

if (EXresource.ContainsKey(EXid.Value))

Dictionary.ContainsKey()