I normally use this notation to define my tables
namespace domain.Entities
{
[Table("seg_modulos")]
public class modulo
{
[Column("modID")]
[Key]
public int modID { get; set; }
[Column("modulo")]
public string modname { get; set; }
}
}
but the ContextBase requires me for some unknown reason that I have a [KEY] to be able to do the dbset
public DbSet<modulo> modulo { get; set; }
For security purposes in my system I want to call a view, it will only make queries, is there a tag like TABLE in DataAnotation, View does not work for me, does anyone know what it is or an alternative way to do it?
thanks if I find out before I post the answer greetings to the community
Alright there is no such thing as a Data annotation for view so I found the way to do it eye this for asp core 3.x EF Core.
1) The first because it gives me an error if I don't define a KEY
because the EF automatically looks for an ID so in the views it does it too and that's why it gave me an error that there was no ID. So what we have to do is the following: 2) We create the entity without data annotation
Then in the Dbcontext we must tell it that it is a view not a table and we do that by modifying the OnModelCreating
You can see that for the view "permisosview" we don't tell it that there is no key "HasNoKey" and we define the columns and the name of the view in the database. now we can easily use the dbset
and Well that's how we use views with EF Core 3.x for 2.x it's different "DbQuery" is used I hope someone helps greetings