选择特定entityState的Poco类列表

时间:2013-05-22 13:02:05

标签: entity-framework ef-code-first change-tracking

我有一个软件正在向上下文添加条目。 使用changetracker我想生成一个Poco类列表用于报告目的。

像这样:

List<customRecord> addedRecords = context.ChangeTracker.Entries<customRecord>().Where(e => e.State == EntityState.Added).ToList();

结果是以下错误:

Cannot implicitly convert type 'System.Collections.Generic.List<System.Data.Entity.Infrastructure.DbEntityEntry<T>>' to 'System.Collections.Generic.List<T>'

有某种方法可以达到这个目的吗?

亲切的问候。

1 个答案:

答案 0 :(得分:1)

添加.Select(i => i.Entity)

List<customRecord> addedRecords = context.ChangeTracker.Entries<customRecord>().Where(e => e.State == EntityState.Added).Select(i => i.Entity).ToList();