【发布时间】:2018-09-10 19:10:58
【问题描述】:
我尝试通过调用存储过程来使用 EF Core 加载实体。 实体通过流式映射映射到一个表,该表不包含存储过程选择的所有列。
在实体配置中忽略不作为表列存在的选定字段,如下所示:
modelBuilder.Entity<CustomerLocationEntity>().Ignore(c => c.Latitude);
modelBuilder.Entity<CustomerLocationEntity>().Ignore(c => c.Longitude);
modelBuilder.Entity<CustomerLocationEntity>().Ignore(c => c.Radius);
modelBuilder.Entity<CustomerLocationEntity>().Ignore(c => c.Distance);
存储过程是这样调用的:
await SalesContext.CustomerLocation
.FromSql("GetCustomersByLocation @latitude={0}, @longitude={1}, @radius={2}", lat,
lon, radius)
.ToListAsync();
执行查询时,忽略的列不会映射到实体。在调用存储过程时是否有可能将忽略的字段映射到实体,或者我是否必须为存储过程创建另一个实体或类似的东西?
【问题讨论】:
标签: c# entity-framework entity-framework-core