问题
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?
回答1:
You've probably missed the following part of the Note at the very beginning of the linked documentation topic
The
[Keyless]
Data Annotation became available in EFCore 5.0.
"became"? "in EFCore 5.0"? Come on, there is no EFCore 5.0 at this time.
Anyway, looks like they are proactively documenting future things, so just be aware of that when something is missing or is different than the documented.
回答2:
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
来源:https://stackoverflow.com/questions/61396213/entity-framework-keyless-data-annotation-missing