Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Question about one-to-one generated code #74

Closed
Azramis opened this issue May 6, 2019 · 4 comments
Closed

Question about one-to-one generated code #74

Azramis opened this issue May 6, 2019 · 4 comments
Labels
bug Confirmed bug question Requesting information released Issue is resolved in a current release

Comments

@Azramis
Copy link

Azramis commented May 6, 2019

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 ?

@msawczyn
Copy link
Owner

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.

@msawczyn msawczyn added bug Confirmed bug question Requesting information workaround available There's a problem that needs fixed, but a procedure can currently be used to get the same result labels May 15, 2019
@Azramis
Copy link
Author

Azramis commented May 20, 2019

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 ?

@msawczyn msawczyn added the pending release Issue is resolved in the current codebase, will be published with the next release label Jul 5, 2019
@msawczyn
Copy link
Owner

msawczyn commented Jul 5, 2019

Fixed in 1.3.0.4

@msawczyn msawczyn added released Issue is resolved in a current release and removed pending release Issue is resolved in the current codebase, will be published with the next release workaround available There's a problem that needs fixed, but a procedure can currently be used to get the same result labels Jul 12, 2019
@msawczyn
Copy link
Owner

Closing since fix was released.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Confirmed bug question Requesting information released Issue is resolved in a current release
Projects
None yet
Development

No branches or pull requests

2 participants