How can I use a sql server view in asp.net core 2?

0

I did a view in sql server of several tables that I use very concurrent among them, my problem is that in asp.net core 2 I can only use the tables of my base with linq or EF from a context and their models that genre with Scaffold-DbContext, how could I use these views?

    
asked by Karla Huerta 22.04.2018 в 21:12
source

1 answer

1

Well you should do it manually, the first thing is to create the model, then add it in the context.cs as are the other tables.

Example

public class Nombre_vista
{
public int Id { get; set; }
public string Nombre { get; set; }
public string Apellido { get; set; }

}

Add to context

public virtual DbSet<Nombre_vista> Nombre_vista { get; set; }

Then in the OnModelCreating method

protected override void OnModelCreating(ModelBuilder modelBuilder)
{

modelBuilder.Entity<Nombre_vista>(entity => { entity.HasKey(e => e.Id); });

}

That way it must work, so I did it last time.

    
answered by 24.04.2018 в 05:05