'Entity Framework, multiple views to same model

I have multiple views (9 or so) that all return the same columns, and in EF I want to map them to the same model. I reverse engineered my ef code with EF Power Tools which gave me multiple models with the same fields, so I want to just use one model instead. However, with the way I currently have it, my DbSet only contains the items from the last built model. Basically, it's like this:

View1
ID int,
Name varchar(100)

View2
ID int,
Name varchar(100)

public virtual DbSet<Person> Persons{ get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
        modelBuilder.Entity<Person>(entity =>
        {
            entity.ToView("View1", "dbo");
            //...
        });

        modelBuilder.Entity<Person>(entity =>
        {
            entity.ToView("View2", "dbo");
            //...
        });
}

When I view Persons, it only has data from View2 in it. I'm not sure if this is even possible in ef, let alone how to do it.

I know I could union all the views in another view and map that one, but I'm trying to use as little sql as possible.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source