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

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
steffen_w
Posts: 16
Joined: Wed 06 Mar 2013 14:28

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

Post by steffen_w » Fri 01 Apr 2016 08:58

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?

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

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

Post by Shalex » Fri 01 Apr 2016 12:59

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.

steffen_w
Posts: 16
Joined: Wed 06 Mar 2013 14:28

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

Post by steffen_w » Fri 01 Apr 2016 13:14

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?

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

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

Post by Shalex » Mon 04 Apr 2016 14:27

For the OneToMany association, you can implement the following scenarios:
nullable<uint> -> nullable<uint>
uint -> uint

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

steffen_w
Posts: 16
Joined: Wed 06 Mar 2013 14:28

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

Post by steffen_w » Mon 11 Apr 2016 09:21

uh, could you fix that? I really don't want a nullable primary key...

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

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

Post by Shalex » Tue 12 Apr 2016 15:45

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?

Post Reply