Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

c# - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...