views:

371

answers:

2

I'm programmatically creating an edmx file as part of our code generation process and I'd like to know how the designer decides to use "1" or "0..1" for a relationship when you "Update model from database". Any insight on this? Thanks

Edit:

Ok, I think it uses "0..1" when the "many" side is a nullable foreign key and "1" if it's not nullable. Can anyone confirm this?

+2  A: 

Yes, setting "0..1" or "1" for the Parent relation role depends upon the fact whether the column is nullable or not.
Don't forget that if the relation is built over parts of primary key columns from both tables(1 to 1 association) the cardinality will be 1 (Parent) to 0..1 (Child).
If you are developing a new edmx-generation tool, we recommend you to experiment and analyze as much as possible. We have developed a design time tool for generating and editing Entity Framework and LINQ to SQL models with further code generation for Oracle, MySQL, PostgreSQL, SQL Server and SQLite for our customers. There were no problems with SQL Server, because Entity Framework was initially developed over it, but other databases revealed some difficulties. There even was an impression that some peculiarities of Oracle database,for example, were not taken into account at all.

Devart
A: 

Your edit is spot on. The EF detects it based on whether or not the field is nullable.

David Pfeffer