Generated code differs from design models

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
RobertK
Posts: 109
Joined: Thu 02 Mar 2017 05:44

Generated code differs from design models

Post by RobertK » Fri 12 Feb 2021 06:01

Saved the efml file and generated the class models - but the class models is different? but inside the efml it is correct.

Design model
https://pasteboard.co/JNYala4.png

Generated code (ApplicationDbContext) - incorrect (contains multiple required properties)
https://pasteboard.co/JNY5D6G.png

Data Models - Correct
https://pasteboard.co/JNY6KOZd.png

---
The model saved matches the code generated but it does not match the diagram - why?

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<efcore context-namespace="Test.Infrastructure.Data" schema="public" namespace="Test.DataModels" p1:name="ApplicationDbContext" p1:Guid="9cdff124-e258-414b-bf0a-973c55324957" xmlns:p1="http://devart.com/schemas/EntityDeveloper/1.0">
  <class name="Card" entity-set="Cards" table="card" p1:Guid="3f7c4b05-3f9c-4f51-be31-8a0db0118c75">
    <id name="Id" type="Guid" p1:ValidateRequired="true" p1:Guid="9f77f3c8-732c-40cd-a2c4-bc841557ff13">
      <column name="id" not-null="True" sql-type="uuid" p1:unicode="False" />
    </id>
    <property name="Nickname" type="String" p1:ValidateRequired="true" p1:Guid="9d6bac45-0370-4239-ac0c-6d5df3d6b606">
      <column name="nickname" not-null="False" sql-type="varchar" p1:unicode="True" />
    </property>
    <property name="FirstName" type="String" p1:nullable="True" p1:ValidateRequired="false" p1:Guid="a3828844-6945-40ec-9d87-b0fc7c202881">
      <column name="first_name" not-null="False" sql-type="varchar" p1:unicode="True" />
    </property>
    <property name="LastName" type="String" p1:nullable="True" p1:ValidateRequired="false" p1:Guid="5e546779-c978-4ab8-9641-d673d0b8786f">
      <column name="last_name" not-null="False" sql-type="varchar" p1:unicode="True" />
    </property>
    <property name="Name" type="String" p1:nullable="True" p1:ValidateRequired="false" p1:Guid="24a6bb13-14de-4182-bf48-f2e39ad9de65">
      <column name="`name`" not-null="True" sql-type="varchar" p1:unicode="True" />
    </property>
    <property name="Number" type="String" p1:nullable="True" p1:ValidateRequired="false" p1:Guid="761505f8-c635-4f0f-ac26-3c7ed5a20a08">
      <column name="`number`" not-null="True" sql-type="varchar" p1:unicode="True" />
    </property>
    <property name="ExpirationMonth" type="Int32" p1:nullable="True" p1:ValidateRequired="false" p1:Guid="2ae957ae-60d2-40c2-8f12-2846991f61b6">
      <column name="expiration_month" not-null="True" sql-type="int4" p1:unicode="False" />
    </property>
    <property name="ExpirationYear" type="Int32" p1:nullable="True" p1:ValidateRequired="false" p1:Guid="0a4ef804-7f23-433d-9afa-78d6da0eef07">
      <column name="expiration_year" not-null="True" sql-type="int4" p1:unicode="False" />
    </property>
    <property name="BillingAddressLine1" type="String" p1:nullable="True" p1:ValidateRequired="false" p1:Guid="12822ba6-9da1-4d27-962f-b5fb40afcc23">
      <column name="billing_address_line1" not-null="True" sql-type="varchar" p1:unicode="True" />
    </property>
    <property name="BillingAddressLine2" type="String" p1:nullable="True" p1:ValidateRequired="false" p1:Guid="11257559-cac3-4d51-b4d8-be7248b59ada">
      <column name="billing_address_line2" not-null="False" sql-type="varchar" p1:unicode="True" />
    </property>
    <property name="BillingCountryState" type="String" p1:nullable="True" p1:ValidateRequired="false" p1:Guid="0d4708d8-6e46-432e-8c1a-f305053ed1ab">
      <column name="billing_country_state" not-null="False" sql-type="varchar" p1:unicode="True" />
    </property>
    <property name="BillingTownCity" type="String" p1:nullable="True" p1:ValidateRequired="false" p1:Guid="03f68526-7241-48b0-83cd-d7c591106c30">
      <column name="billing_town_city" not-null="True" sql-type="varchar" p1:unicode="True" />
    </property>
    <property name="BillingPostalCode" type="String" p1:nullable="True" p1:ValidateRequired="false" p1:Guid="02739016-402d-4a99-a9cd-4f7f03e6acaf">
      <column name="billing_postal_code" not-null="True" sql-type="varchar" p1:unicode="True" />
    </property>
    <property name="BillingCountry" type="String" p1:nullable="True" p1:ValidateRequired="false" p1:Guid="5ec6aa5b-f87a-47c7-92fd-fea6f8b51078">
      <column name="billing_country" not-null="False" sql-type="varchar" p1:unicode="True" />
    </property>
    <property name="MetaData" type="String" p1:nullable="True" p1:ValidateRequired="false" p1:Guid="6a3e0473-d959-4044-ac85-dce9ad4a18d4">
      <column name="meta_data" not-null="True" sql-type="varchar" p1:unicode="True" />
    </property>
  </class>
</efcore>

RobertK
Posts: 109
Joined: Thu 02 Mar 2017 05:44

Re: Generated code differs from design models

Post by RobertK » Sat 13 Feb 2021 06:56

I just checked, when i save the model it saves to the file, but when the code is generated it do something else - very odd!

Shalex
Site Admin
Posts: 9307
Joined: Thu 14 Aug 2008 12:44

Re: Generated code differs from design models

Post by Shalex » Sat 13 Feb 2021 13:36

RobertK wrote: Fri 12 Feb 2021 06:01 The model saved matches the code generated but it does not match the diagram - why?
We cannot reproduce any issue with Entity Developer v6.10.1165.
1. Please send us a test model for reproducing the issue.
2. Specify the class properties we should pay attention to.
3. Are you using a standalone Entity Developer or the one integrated into Visual Studio?

RobertK
Posts: 109
Joined: Thu 02 Mar 2017 05:44

Re: Generated code differs from design models

Post by RobertK » Sun 14 Feb 2021 13:55

Download: https://filebin.net/5bz15qlz87r2e146

There is only one table "card"

Test.Card.cs - correct code is generated.
Test.ApplicationDbContext.cs - incorrect code is generated (it does not match the entity developer models)

Code generated using standalone Entity Developer.

Shalex
Site Admin
Posts: 9307
Joined: Thu 14 Aug 2008 12:44

Re: Generated code differs from design models

Post by Shalex » Sat 20 Feb 2021 19:09

Thank you for the test model. We will investigate the issue and notify you about the result.

RobertK
Posts: 109
Joined: Thu 02 Mar 2017 05:44

Re: Generated code differs from design models

Post by RobertK » Thu 25 Feb 2021 16:39

where you able to download the files?

im using postgres and ef core template, standalone entity developer

Shalex
Site Admin
Posts: 9307
Joined: Thu 14 Aug 2008 12:44

Re: Generated code differs from design models

Post by Shalex » Fri 26 Feb 2021 10:31

RobertK wrote: Thu 25 Feb 2021 16:39 where you able to download the files?
We have downloaded the files and reproduced the issue. The investigation is in progress.

RobertK
Posts: 109
Joined: Thu 02 Mar 2017 05:44

Re: Generated code differs from design models

Post by RobertK » Wed 03 Mar 2021 16:05

Shalex wrote: Fri 26 Feb 2021 10:31
RobertK wrote: Thu 25 Feb 2021 16:39 where you able to download the files?
We have downloaded the files and reproduced the issue. The investigation is in progress.
Are there any work around?

Shalex
Site Admin
Posts: 9307
Joined: Thu 14 Aug 2008 12:44

Re: Generated code differs from design models

Post by Shalex » Fri 12 Mar 2021 09:26

We are looking for a solution in the case of conflicting settings for class property's Nullable and column's Not Null.

As a workaround, synchronize these two settings for each property manually.

RobertK
Posts: 109
Joined: Thu 02 Mar 2017 05:44

Re: Generated code differs from design models

Post by RobertK » Wed 17 Mar 2021 11:47

Shalex wrote: Fri 12 Mar 2021 09:26 We are looking for a solution in the case of conflicting settings for class property's Nullable and column's Not Null.

As a workaround, synchronize these two settings for each property manually.
did you figure out a solution how to resolve this issue where code generated does not match model?

RobertK
Posts: 109
Joined: Thu 02 Mar 2017 05:44

Re: Generated code differs from design models

Post by RobertK » Thu 18 Mar 2021 01:43

the only solution i have right now is to edit the .efml file, but then when i make changes to the model, I would experience the same issue all over again, so it is not ideal, unable to use entity developer until this issue is fixed.

Is this only an issue with the standalone version of entity developer?

Shalex
Site Admin
Posts: 9307
Joined: Thu 14 Aug 2008 12:44

Re: Generated code differs from design models

Post by Shalex » Thu 18 Mar 2021 13:13

RobertK wrote:did you figure out a solution how to resolve this issue where code generated does not match model?
Please adjust values of class property's Nullable and column's Not Null manually. Or run Regenerate Storage and Mapping via the context menu of your model. We are looking for a solution for new models.
RobertK wrote:the only solution i have right now is to edit the .efml file, but then when i make changes to the model, I would experience the same issue all over again, so it is not ideal, unable to use entity developer until this issue is fixed.
You can do that in design-time via Property Editor and Column Editor.
RobertK wrote:Is this only an issue with the standalone version of entity developer?
The behavior is the same for both the standalone Entity Developer and the one embedded into Visual Studio.

RobertK
Posts: 109
Joined: Thu 02 Mar 2017 05:44

Re: Generated code differs from design models

Post by RobertK » Sun 21 Mar 2021 11:42

Shalex wrote: Thu 18 Mar 2021 13:13
You can do that in design-time via Property Editor and Column Editor.
The problem is it does not work, i.e I make changes in entity developer it will save some new tables and new columns in the .efml but sometimes I make changes to older columns and no changes will be reflected in the .efml file. This inconsistency is a problem, i can no longer use the product, because i dont know if the generated code matches the models anymore.

"run Regenerate Storage and Mapping via the context menu of your model. We are looking for a solution for new models."

Regenerating storage and class model? I can not create new models from the database, because I often map out the diagram and recreating it will destroy my diagrams.

Shalex
Site Admin
Posts: 9307
Joined: Thu 14 Aug 2008 12:44

Re: Generated code differs from design models

Post by Shalex » Mon 22 Mar 2021 18:09

RobertK wrote: The problem is it does not work, i.e I make changes in entity developer it will save some new tables and new columns in the .efml but sometimes I make changes to older columns and no changes will be reflected in the .efml file.
There is a known problem with saving *.efml in .NET Core Visual Studio projects.
Current workarounds:
a) save the model in VS2019 via File > Save As and leave the original name
b) or close the model window in VS2019, prompt windows will ask to save changes
c) or use the standalone version of Entity Developer

If this is not the case, send us a test project and specify the steps for reproducing the issue.
RobertK wrote: Regenerating storage and class model? I can not create new models from the database, because I often map out the diagram and recreating it will destroy my diagrams.
The Regenerate Storage and Mapping wizard recreates database mapping in model basing on the existing model classes.

RobertK
Posts: 109
Joined: Thu 02 Mar 2017 05:44

Re: Generated code differs from design models

Post by RobertK » Tue 23 Mar 2021 14:44

Thread moved here viewtopic.php?f=32&t=44660

Post Reply