msawczyn / EFDesigner

Entity Framework visual design surface and code-first code generation for EF6, Core and beyond
MIT License
363 stars 60 forks source link

generation error on BiDirectionnal Association #285

Closed pas059 closed 3 years ago

pas059 commented 3 years ago

Hi, Using EF designer vers 3.0.5.2 with VS 2019CE vers 16.9.5, the code is badly generated on BiDirectionnal association ( many to 1). For instance, the code in the constructor is generated like this:

     public Profession()
      {
          = new System.Collections.Generic.HashSet<global::WinFormsEFcDes1.Referent>();

         Init();
      }

instead of:

     public Profession()
      {
         Referents = new System.Collections.Generic.HashSet<global::WinFormsEFcDes1.Referent>();

         Init();
      }

Referents being the corrresponding navigation property.

regards

SimGoesMad commented 3 years ago

Hi, I have been facing the same issue for a few hours now. I did manage to make it go away, but I don't know if this is a solution per se.

I had a 1:* bidirectional association and if I select the model (sorry, had a typo here before) itself (not the association) and set the "AutoProperty Default" to False, it worked by generating the missing bit of the code ( ie. _mycollection = System.Collections......)

HTH.

pas059 commented 3 years ago

Hi, Exact SimGoesMad, by setting "AutoProperty Default" to False, this error no longer appears,... but the OnModelCreating() function is generated very differently which products hundreds of compilation errors from this function; so, this is not a woraround for me.

If this can help, the code is badly generated only in the default constructors, not in the others.

Regards

msawczyn commented 3 years ago

Thanks for reporting this. It's been resolved in the latest pre-release at https://github.com/msawczyn/EFDesigner/releases/tag/v3.0.6.1-nightly

If, by the end of today, I can't find any glaring errors in that pre-release I'm going to push it to the Marketplace as 3.0.6

pas059 commented 3 years ago

thanks, code is correctly generated with 3.0.6. regards