4

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?

Community
  • 1
  • 1
Craig Walker
  • 49,871
  • 54
  • 152
  • 212

1 Answers1

2

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
  • 49,871
  • 54
  • 152
  • 212
  • I definitely do not want to do this as we refresh our dbml file regularly and it would get overwritten. Did you ever find a better way? – JumpingJezza Aug 04 '11 at 05:06
  • Nope, never did, though I stopped looking long ago. Perhaps your dbml-refreshing tool can be set to reimplement this change? – Craig Walker Aug 04 '11 at 05:24