Entity framework core 如何对';FromSql()';对基本数据类型的查询?
我正在使用EF Core 3.1中的无键实体类型功能。我想把一些表数据映射到我的实体类中。 这是我的Entity framework core 如何对';FromSql()';对基本数据类型的查询?,entity-framework-core,Entity Framework Core,我正在使用EF Core 3.1中的无键实体类型功能。我想把一些表数据映射到我的实体类中。 这是我的db上下文config: public class HimartWarehouseReportContext: DbContext { public HimartWarehouseReportContext() { } public HimartWarehouseReportContext(DbContextOptions<HimartWarehou
db上下文
config:
public class HimartWarehouseReportContext: DbContext
{
public HimartWarehouseReportContext()
{
}
public HimartWarehouseReportContext(DbContextOptions<HimartWarehouseReportContext> options)
: base(options)
{
}
public DbSet<MarketPresence> MarketPresence { get; set; }
public DbSet<Campaign> Campaign { get; set; }
public DbSet<CampaignDt> CampaignDt { get; set; }
public DbSet<List<String>> Category { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<MarketPresence>().HasNoKey().ToView(null);
modelBuilder.Entity<Campaign>().HasNoKey().ToView(null);
modelBuilder.Entity<List<String>>().HasNoKey().ToView(null);
}
}
但是关于最后一个案例类别
,我只想返回字符串列表作为我的sql查询的结果,我得到异常消息:所需的列“Capacity”在“FromSql”操作的结果中不存在。
(capacity是我的sql结果查询的名称,查询的结果是一个名为capacity的单列表)
我怎样才能想出这个问题
感谢您的关注。我有一些类似的东西,只是创建了一个类似于您的Category类的类,包含数百个属性。这是我能想到的最简单的方法。请将代码和数据添加为文本(),而不是图像。图像:a)不允许我们复制和粘贴代码/错误/数据以进行测试;B) 不允许基于代码/错误/数据内容进行搜索;和。如果图像添加了一些仅由文本代码/错误/数据无法传达的重要信息,则除了代码格式的文本外,还应使用图像。
public IEnumerable<Campaign> GetCampaignReports(Campaign input)
{
var result = _reportContext
.Campaign
.FromSqlRaw("GetCampaignReport " +
$"{input.ProvinceId}, " +
$"{input.CityId}")
}