Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework - [Keyless] Data Annotation Missing

According with the Microsoft Documentation Here, I should have access to the Attribute for [Keyless] so I can define my Model has Keyless, so that in my DBContext I could have something like:

public DbSet<MyKeylessClass> KeylessModel { get; set; }

And use _context.KeylessModel.FromSqlRaw(...), without having the need to add a PK to it. I have the reference to System.ComponentModel.DataAnnotations and all the Attributes except Keyless are there, what am I missing here?

like image 307
Ricardo Dias Morais Avatar asked Apr 23 '20 20:04

Ricardo Dias Morais


1 Answers

Well, the official EF Core 3.0 release documentation doesn't say a word about supporting that attribute yet, instead for keyless types they instruct to use HasNoKey() method:

ModelBuilder.Entity<MyKeylessClass>().HasNoKey()

You can read more here

like image 177
E-Bat Avatar answered Oct 01 '22 02:10

E-Bat