1 回答
TA贡献1827条经验 获得超8个赞
当您在列上使用fluent api的忽略方法时,它不会在sql server中创建该列(忽略它)。
您的存储过程结果将根据您创建的查询为您提供一些列,并且这些列名称必须与您的实体上的属性名称匹配。
例如,您的过程为您提供了一个包含这些列的表以及 sql server 和您的类中的匹配数据类型:
纬度
经度
半径
距离
然后你应该为你的过程创建一个类:
public class LocationProcedure {
public string Latitude {get;set;}
public string Longitude {get;set;}
public string Radius {get;set;}
public string Distance {get;set;}
}
并使用[NotMapped]属性将这种类型的数据库集添加到您的 dbContext 中:
[NotMapped]
public DbSet<LocationProcedure> CustomerLocation {get; set:}
该属性告诉这不应该是数据库中的表。
最后,您可以将您的过程与新的 dbset 一起使用CustomerLocation,然后它将结果映射到LocationProcedure类。
await SalesContext.CustomerLocation
.FromSql("GetCustomersByLocation @latitude={0}, @longitude={1}, @radius={2}", lat,
lon, radius)
.ToListAsync();
- 1 回答
- 0 关注
- 625 浏览
添加回答
举报
