6

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?

3 Answers 3

8

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

Sign up to request clarification or add additional context in comments.

2 Comments

i'm aware of that method, and yes it works if someone is wondering, my doubt was really about the Attribute, i read it and also went in more depth on the issues in the EF github, and found something similar to what you said, but it was on the early days of this new feature release, to be fair, this is relatively new also, but I expected since it was documented it had been implemented, i'm not marking as the correct anwser just for that, but if no solution comes on i will check it don't worry, thank you for your time
@RicardoDiasMorais I understand what you say, I couldn't find the attribute myself, tbh I've never used it, but be aware the documentation you pointed looks aimed to EF 2.1, when Query types was the recommended approach, now they are deprecated in favor of DbSet, like it was before 2.1 :).
2

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.

7 Comments

Yes, the docs suggest there's a stable 5.0 version. So far, there's only a preview.
@Gert Indeed. The docs are mess if you ask me - the docs for previous versions are lost (thus breaking the links or showing different content), some things for the current version are outdated missing, and now refer to future (non released) things. Even the root page has been changed, so now "Entity Framework" refers to EF Core, and EF6 is under "Previous Versions". Etc. :-(
That's what happens when marketing gets a finger in the pie :) They're happier with EF core than I am.
@IvanStoevo This is the correct answer what you said here: -now "Entity Framework" refers to EF Core, and EF6 is under "Previous Versions", so i'm marking this as the CA
@E-Bat Sorry for the delayed response, but I disagree with your statement. My question, in a brief way, was "Why the Keyless Attribute missing if I have the correct reference", I was aware of other possible solutions, like the one you gave, I even stated in a comment. This answer does it really well on why that was happening, and there's nothing wrong with yours either, both are simple and informative.
|
1

It's there now if you have ef 5.x but it's not under regular data annotations namespace, try this: [Microsoft.EntityFrameworkCore.Keyless]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.