EF core using views

To access database view using DbContext, you just need to :

1. POCO - Create your POCO using code shown below. Please note that you need to match exactly the POCO to your views but not necessary all the fields. Let's say you have 10 fields but you can just defined 3 that is of interest to you :

2. Add your DbSet - You need to open up your DBContext and add in your DbSet Manually.

  public virtual DbSet VwValuations { get; set; }

3.OnModelCreating - in your DbContext, add your valuations data as shown below :

The data type used depends on your view.

That should be all the changes you need to make.


Popular posts from this blog

ionic2 cordova build android - Unable resolve gradle 2.2.3

A quick tutorial for OWASP ZAP tool for beginners

OpenCover code coverage for .Net Core