I am having an issue where my project works on the current database, but when I use the code in my application to create a new database vis acode first, classes that were accessing views, are now being creating tables. Classes below have been shortened by removing other properties to show just relevant code.
I have a my DBContextClass:
public class MyDbContext : DbContext
{
public MyDbContext ()
{
}
public virtual DbSet<Order> Order{ get; set; }
public virtual DbSet<v_OrdersByUser> v_OrdersByUsers { get; set; }
}
Here is my Order class:
[Table("Orders")]
public class Order
{
[Key]
public int Id { get; set; }
etc
}
which creates a table as expected. But here is my SQL view class:
public class v_OrdersByUser
{
[Key]
public string UserName { get; set; }
public int OrdersCount { get; set; }
}
but this class also creates a table.
How do I stop this from happening, yet maintain the ability to access the views, once I create them in the database?