views:

128

answers:

1

I have two objects (Foo and Bar) that have a one-to-zero-or-one relationship between them. So, Foo has a nullable foreign key reference to Bar.ID and a (nullbusted) unique index to enforce the "1" side. Bar.ID is an int, and so Foo.BarID is a nullable int.

The problem occurs in the LINQ-to-SQL DBML mapping of .NET types to SQL datatypes. Since int is not a nullable type in .NET, it gets wrapped in a Nullable<int>. However, this is not the same type as int, and so Visual Studio gives me this error message when I try to create the OneToOne Association between them:

Cannot create an association "Bar_Foo". Properties do not have matching types: "ID", "BarID".

Is there a way around this?

+1  A: 

So far I've worked around this by setting Bar.ID (the primary key) to CanBeNull="true", which is definitely ugly. I'm hoping for a better solution here.

Craig Walker