gpt4 book ai didi

c# - 我怎样才能让 EF 在保存时更新我的​​ ModifiedDate?

转载 作者:太空宇宙 更新时间:2023-11-03 16:17:23 27 4
gpt4 key购买 nike

我有以下用途:

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();
}

但是这会出错,我不明白为什么。错误信息是说

Error 3 'System.Collections.Generic.IEnumerable' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?)

最佳答案

请导入 System.Linq 命名空间

关于c# - 我怎样才能让 EF 在保存时更新我的​​ ModifiedDate?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15402677/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com