How do I add default constructors to the entity classes?
See original GitHub issueI would like to have the default constructor be like this if possible
If I can modify a template or something simple I will do it. I use the context often for the partial classes and EF 6 Core doesn’t have an easy way to access the entity context like I was able to in EF6. If I can add the constructor with the context simply then EF 6 will DI the parameters as needed.
public partial class MyDbContext
{
protected MyDbContext Context;
public MyEntity(MyDbContext context)
{
Context = context;
}
/****
Properties Code.....
***/
}
Issue Analytics
- State:
- Created a year ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Need for Default Constructor in JPA Entities
In this quick tutorial, we'll learn about the JPA requirement for a default no-argument constructor in an Entity class.
Read more >JPA: is the default constructor required to be empty?
When you are creating a "new" object, the constructor needs to produce an object that is sufficiently initialized to be used by normal...
Read more >Default Constructor in Java – Class Constructor Example
In this article, we will talk about constructors, how to create our own constructors, and what default constructors are in Java.
Read more >Entity types with constructors - EF Core
Using constructors to bind data with Entity Framework Core model. ... it will first call the default parameterless constructor and then set ......
Read more >Chapter 4. Entity
Default or No-Arg Constructor. The JPA specification requires that all persistent classes have a no-arg constructor. This constructor may be public or protected ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I do not think there is any compelling reason to do this, lazy loading is possible with EF Core using other means, and you can always create partial classes with the constructor as needed.
@glenlewisdd The pattern of injecting a DBContext into entities looks suspect to me. What is it you are trying to accomplish?