I'd like to use a view to add information to a table like this
public class PocoTable
{
public int Id { get; set; }
}
public partial class ImportStatingRecordError : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"
CREATE VIEW PocoView
AS
SELECT Id, ISNULL(l.InterestingValue, '?') AS InterestingValue
FROM PocoTable t
LEFT JOIN OtherTable o ON t.Id = o.PocoTableId
");
}
}
public class PocoView : PocoTable
{
public string InterestingValue { get; set; }
}
public class ApplicationDbContext : DbContext
{
public DbSet<PocoTable> PocoTables { get; set; }
public DbSet<PocoView> PocoViews { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<PocoView>().ToView("PocoView").HasKey(z => new z.Id);
}
}
But EntityFramework (core) isn't having any of it because:
The entity type 'PocoView' cannot be mapped to a table because it is derived from 'PocoTable'. Only base entity types can be mapped to a table.
Can this be made to work? Or can I do this some other way?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…