Skip to content

Instantly share code, notes, and snippets.

@KarateJB
Created July 22, 2020 11:11
Show Gist options
  • Save KarateJB/a00a6d0d7270b17a983a22dc4a125cca to your computer and use it in GitHub Desktop.
Save KarateJB/a00a6d0d7270b17a983a22dc4a125cca to your computer and use it in GitHub Desktop.
[ASP.NET Core 2.2] EF Core View example
[Table("VwDatas")]
public class VwData
{
public string Name { get; set; }
public int Cnt { get; set; }
}
public class MyDbContext : DbContext
{
public MyDbContext(DbContextOptions<MyDbContext> options)
: base(options)
{
}
// public DbSet<MyPoco> MyPocos { get; set; }
public DbQuery<VwData> VwDatas { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Ignore<VwData>();
modelBuilder.Query<VwData>().ToView("VwDatas");
}
}
var dbContext = new MyDbContext;
var entities = dbContext.Query<VwData>().ToList();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment