2

我有以下使用:

using System;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;

和以下代码:

   public override int SaveChanges() 
    {
    foreach (var stateinfo in this.ChangeTracker.Entries(DataContext)
        .Where(e => e.Entity is StateInfo && (e.State == EntityState.Added || e.State ==  EntityState.Modified))
        .Select(e => e.Entity as StateInfo))
    ) {
        stateinfo.ModifiedDate = DateTime.Now;
       }
    return base.SaveChanges();
    }

然而,这给出了一个错误,我不明白为什么。错误消息是它说

错误 3“System.Collections.Generic.IEnumerable”不包含“Where”的定义,并且找不到接受“System.Collections.Generic.IEnumerable”类型的第一个参数的扩展方法“Where”(您是否缺少使用指令还是程序集引用?)

4

2 回答 2

0

请导入System.Linq namespace

于 2013-03-14T06:33:37.333 回答
0

由于Enumerable.Where<T>方法属于 System.Linq命名空间,因此您需要将其添加到代码顶部。来自MSDN

Namespace:  System.Linq
Assembly:  System.Core (in System.Core.dll)

But.. come on, this is really a basic issue. You can find your solution using Google with just takes a few seconds. Please show a little more effort to solve the problems ;)

于 2013-03-14T06:36:30.433 回答