king612 (4) [Avatar] Offline
#1
I am repeated getting this runtime error (not compile time, I guess because it involves attributes?) on more than one class. My object model is not trivial, for example multiple foreign keys from one table that point to the same primary table, but I have double and triple checked all my foreign keys in the DB, and I'm confident they are all set up correctly.

The full runtime error message is:

"The number of ThisKey columns is different from the number of OtherKey columns for the association property 'Foo' in the type 'Bar'."


Googled it to death but couldn't find anybody else getting this error.


I see examples where the attributes on associations have both 'ThisKey' and 'OtherKey', but mine all look like this:

... ThisKey="FooID", IsForeignKey=true)]

I'm using the O/R designer in VS 08 and SQL Server 2005.

Help!

Thanks,
John
king612 (4) [Avatar] Offline
#2
Re: Number of ThisKey columns is different from the number of OtherKey colu
Figured this one out myself - this is the error message you get when you violate the restriction in Linq to SQL about all inheritance having to use Table-per-hierarchy mapping. We were using Table-per-subclass (using NHibernate, where it works just fine). Interestingly, the subclasses work just fine, because the FK's are based on them anyway. As soon as you drop in the super class it breaks, but the compiler doesn't catch it. It is apparently some check done at runtime.

John

(Come on EF! When are you going to get here!?)
fabrice.marguerie (224) [Avatar] Offline
#3
Re: Number of ThisKey columns is different from the number of OtherKey colu
Hi John,

Thank you for sharing your findings. Yes, things will be different once EF gets released.

Fabrice