views:

33

answers:

2

After creating an EF4 model from a SQL Server database I noticed that all the relationships of my Users table were not imported into the model as associations. All the other relationships were imported fine.

My Users table has a PK userId which is a char(7) field and it is integrated into several other tables in the database as an FK but for some reason EF4 does not import these relationships as associations during the model generation process...

Does anyone have any ideas why this would be happening?

A: 

My immediate response is that you might have the 'Pluralize or singularize generated object names' checkbox enabled. This is a new checkbox option, so if you are used to generating Entities with older versions of the Entity Framework then you might not realize this is on by default in EF 4. It will break your build if you are not expecting this behavior.

YeahStu
Just deleted the existing model and generated a new one from scratch with 'Pluralize or singularize generated object names' checkbox unchecked and the associations were still not created...
kzen
Ok, good to know. My other suggestion is that the Users table might be involved in a many to many relationship with the tables. In that case, the intermediate table may not be displayed in the associations. Were you always using EF4 with this data model or is the new version potentially causing the problem?
YeahStu
Users table was involved in one many to many relationship but after removing that relationship and creating a new model the associations are still not being generated... This model was always using the EF4.
kzen
+2  A: 

After I changed the UserId field type to int the relationships were correctly imported. It appears that EF4 cannot import char based relationships.

I'll mark this as the answer although it is just a workaround. If someone comes along and provides a correct answer I will gladly change this...

kzen