Page 1 of 1

How can I model a 0...n relationship between two tables?

Posted: Fri 01 Apr 2016 08:58
by steffen_w
Hi,

it's quite surprising, really, but I just had the first situation where I wanted to model a 0...n relation between two tables, and couldn't do it.

At first I tried creating a 1...n relation and checked the 'Nullable' checkbox on the foreign key, but that doesn't work (I get a .NET exception telling me that a conversion between In32 and Nullable<uint> did not succeed, no stacktrace.).

I then decided to search around but couldn't find any option or button or anything to do this.

Does Linq2SQL only support 1..n/n..m/1..1 relations between tables?

Re: How can I model a 0...n relationship between two tables?

Posted: Fri 01 Apr 2016 12:59
by Shalex
steffen_w wrote:At first I tried creating a 1...n relation and checked the 'Nullable' checkbox on the foreign key, but that doesn't work (I get a .NET exception telling me that a conversion between In32 and Nullable<uint> did not succeed, no stacktrace.).
Please set the same type (int or uint) on both sides of your association. If this doesn't help, send us a small test project and specify the steps we should follow for reproducing.

Re: How can I model a 0...n relationship between two tables?

Posted: Fri 01 Apr 2016 13:14
by steffen_w
Both sides were set to uint, but the foreign key was a nullable<uint>.

Just for clarification: Are you saying that a 0..n relationship between two tables is supported?

Re: How can I model a 0...n relationship between two tables?

Posted: Mon 04 Apr 2016 14:27
by Shalex
For the OneToMany association, you can implement the following scenarios:
nullable<uint> -> nullable<uint>
uint -> uint

The nullable<uint> -> uint way is not supported.

Re: How can I model a 0...n relationship between two tables?

Posted: Mon 11 Apr 2016 09:21
by steffen_w
uh, could you fix that? I really don't want a nullable primary key...

Re: How can I model a 0...n relationship between two tables?

Posted: Tue 12 Apr 2016 15:45
by Shalex
Could you please send us a small test project with the corresponding DDL/DML script so that we can better understand your approach and recommend you a workaround?