Entity Framework 6 error - 'Value cannot be null. Parameter name: entitySet'
This piece of code is throwing the above error:
This is my WarningType class:
This is my DbSet in ApplicationDbContext.cs:
I attached the database table picture for WarningTypes.
![No description](https://cdn.answeroverflow.com/1229366803289866320/image.png)
22 Replies
I don't use EF without Dependency Injection. Judging by this code the connection string is not passed which is required.
Consider using DI in your project rather than making a custom instance each time
I already have this on ApplicationDbContext:
And my webconfig contains
Would it not throw an error in the using statement if the connection string was empty or wrong in that case?
Can you send the full code for
WarningType
it seems to be a partial class and the code snippet doesn't include everythingThat's all actually, it's not a partial class, my mistake
are u working with legacy app?
Hmm, can you attach the full stack trace?
Yes, it's a legacy app which was having a few caching issues using some other framework.
Now we're changing it to EF6 temporarily until we move to EF core
And later on when saving the error log I have the text file below
But I don't think the text file is really important because the provided Id at that point is not an actual user
I assume you didn't run migration or anything,the db already exists right?
Yes, the db already exists
What's the table name?
WarningTypes
I also tried adding the attribute [Table("WarningTypes")]
to the WarningType class
But still got the same error
Hmmm, have you tried specifying the
Id
as a Key
with the attribute Key
?Just tried a second time to make sure, but still got the same error