Created
July 22, 2020 11:11
-
-
Save KarateJB/a00a6d0d7270b17a983a22dc4a125cca to your computer and use it in GitHub Desktop.
[ASP.NET Core 2.2] EF Core View example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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