Entity Developer loosing foreign key names

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
PeterWood
Posts: 5
Joined: Thu 17 May 2012 14:59

Entity Developer loosing foreign key names

Post by PeterWood » Thu 17 May 2012 15:14

Hi -

I am trialing Entity Developer Pro v4.3.178, using it model first to create an NHibernate model and apply it to an empty SQL Server 2005 database.

Every entity in my model has a primary key called "ID" (int32). Foreign keys are always to the related primary keys and the column name standard on the referencing table is <ReferencedTableName>ID. eg. ReportComponent has a foreign key to ReportComponentType and I have specified a column name of ReportComponentTypeID.

However, when I apply the model to the database all the foreign key column names I have specified revert to the default "ID". On many-to-many joins this throws an error because ED tries to create a table with two columns named ID.

Seems to obvious to be a bug, but I can't see what I'm doing wrong.

Can anyone help?

Regards,
Peter

Helen
Devart Team
Posts: 127
Joined: Wed 07 Sep 2011 11:54

Re: Entity Developer loosing foreign key names

Post by Helen » Fri 18 May 2012 10:34

It is likely, that when running Update To Database or Generate Database Script wizard you selected "Regenerate storage" check-box.

If the "Regenerate Storage" check-box is selected, the whole Model Storage part and Mapping, including the description of storage columns and ends of relations, is completely re-generated.

In case of NHibernate, all the customization of Columns options and other mapping settings are filled automatically using our engine, converting Conceptual model to the Storage model and Mapping between them. The engine considers entities, associations, and inheritances from the Conceptual model.

When working with NHibernate ORM this option is rarely used because NHibernate runtime does not require the Storage part and Mapping and can work without them. With NHibernate, this option should be used only if you want your Storage part to be always completed, and want it to be done automatically.

PeterWood
Posts: 5
Joined: Thu 17 May 2012 14:59

Re: Entity Developer loosing foreign key names

Post by PeterWood » Thu 24 May 2012 10:15

Thanks, not clicking "Regenerate storage" solved my problem. I am still having a problem with on entity attempting to generate a DATETIME2 field on a SQL 2005 database, even though the field on the entity is defined as DATETIME, but I can work around that.

Helen
Devart Team
Posts: 127
Joined: Wed 07 Sep 2011 11:54

Re: Entity Developer loosing foreign key names

Post by Helen » Thu 24 May 2012 10:56

PeterWood wrote:I am still having a problem with on entity attempting to generate a DATETIME2 field on a SQL 2005 database, even though the field on the entity is defined as DATETIME, but I can work around that.
We suppose that this behaviour is a caused by custom mapping set for columns manually. For example, for the PeriodEndDate column of the PeriodEnd class you specified custom mapping (via Column Editor you have set SQL type=datetime2 NOT NULL ). This is why during the script generation a column is created with type = DATETIME2.

PeterWood
Posts: 5
Joined: Thu 17 May 2012 14:59

Re: Entity Developer loosing foreign key names

Post by PeterWood » Thu 24 May 2012 11:21

Thank you Helen! Not sure how this happened, but you are right.

sdb
Posts: 4
Joined: Sun 14 Oct 2012 12:16

Re: Entity Developer loosing foreign key names

Post by sdb » Fri 19 Oct 2012 05:39

hey, I've also had names of FK colums gone. Rather timeconsuming to manually find & change all of them again :(

Feature request: Why does Entity Developer not suggest a sensible (or at least a working) name for foreign key colums in the first place?

Good in my case would be a FK name of [ReferencedTableName][PKNameOfReferencedTable]. Plus 'allow null' if Foreign key is set on a child class.

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

Re: Entity Developer loosing foreign key names

Post by Shalex » Fri 19 Oct 2012 17:10

1. Do you select the "Regenerate storage" check-box when running Update To Database or Generate Database Script wizard?
2. Which ORM (Entity Framework/LinqConnect/NHibernate) do you use?
3. You set different names for entity property and corresponding table column but after update the name of table column becomes the same as the name of entity property. Is that what you mean?

If the "Regenerate Storage" check-box is selected, the whole Model Storage part and Mapping, including the description of storage columns and ends of relations, is completely re-generated basing on the Conceptual part of the model.

sdb
Posts: 4
Joined: Sun 14 Oct 2012 12:16

Re: Entity Developer loosing foreign key names

Post by sdb » Mon 22 Oct 2012 05:46

Hi Shalex,

1. I implied that "Regenerate storage" means that all available tables in the database are deleted and recreated. This is how/when I used it. I think I used it in both Wizards. "Generate database script" and "update database".
2. I'm using NHibernate
3. I don't understand your sample.
Sample: Class1 has a PK column "Id"
Class2 has a PK column "Id"
Class1 and Class2 have a one to many relation. The default columname (bottom part of dialog - 'columns mapping:') of the foreignkey is "Id" - which doesn't work, because column "Id" is already the PK column. Having it manually changed it to 'Class2Id' and then run 'regenerate storage' renames it back to 'Id'..

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

Re: Entity Developer loosing foreign key names

Post by Shalex » Tue 23 Oct 2012 16:22

sdb wrote:I implied that "Regenerate storage" means that all available tables in the database are deleted and recreated. This is how/when I used it. I think I used it in both Wizards. "Generate database script" and "update database".
The "Regenerate storage" option regenerates only parts of the model and has nothing to do with the database objects. If you want update your database objects, please use Update Database From Model Wizard.
sdb wrote:Having it manually changed it to 'Class2Id' and then run 'regenerate storage' renames it back to 'Id'..
Do not select the "Regenerate storage" option not to update the storage part of your model.

This option in Devart NHibernate Model should be used only when migrating from one database server to another one.

Post Reply