Create your table view in the database. Then using EF FluentAPI to config the view mapping. Here is the sample code:
1. Create POCO class to map:
public class YourView
{
public int Id { get; set; }
public string Value { get; set; }
}
2. EF FluentAPI mapping configuration:
Create map class:
public class YourViewMap : IEntityTypeConfiguration<YourView>
{
public void Configure(EntityTypeBuilder<YourView> builder)
{
builder.ToTable("YourViewName");
}
}
Add mapping configuration to your DbContext (such as AbpCoreDbContext). Override OnModelCreating method:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ApplyConfiguration(new YourViewMap ());
base.OnModelCreating(modelBuilder);
}
3. Get data:
using IRepository<YourView>
to query data from the view.
P.S: related question how to use views in code first entity framework