Question about one-to-one generated code
Azramis opened this issue · 4 comments
Hi,
I have a question about the generated code for a one-to-one relation.
In each entity's constructor, it's required to pass the linked entity.
For example, if I have an entity Student which is linked with a StudentAddress in a one-to-one relation, I have to write a code like this :
var student = new Student(new StudentAdress(new Student(new StudentAdress(...))));
... SaveChanges();
This code doesn't work, so how should I proceed to make this working ?
Circular requirement of entities by constructor is maybe a bug ?
We do need to handle that better. What you can do in the interim is create a custom constructor in the partial that doesn't have the required property involved in the chicken-and-egg scenario. That's what we'll be doing to fix the problem permanently, only it'll be generated rather than custom.
Thanks for the response.
Effectively I use this kind of workaround. Unfortunately, I can't create a constructor with no param, because of the generated one, whom is protected. So I have created a public static method to create an instance of my first class, and set the property after that call.
Maybe the "chicken" class constructor should create the "egg" instance directly to simplify the process ?
Fixed in 1.3.0.4
Closing since fix was released.