views:

925

answers:

3

In the L2S designer I have dropped a table and a view. I tried adding an association between the 2 on their primary keys. This should be a one-to-one relationship, so I set the cardinality property of the association as such.

But, when coding I can't access the child property.

Any suggestions?

Edit

I just created a view in sql server that has the fields I want, and dropped that into L2S. Much simpler.

A: 

Did you disable (set to false) either the child or parent property?

Did you perhaps mapped the one-to-one relationship the wrong way around (like I did less than an hour ago)?

leppie
Child property is true. I have tried both objects as the parent.
Ronnie Overby
Look in the .designer file for the property you expect. Perhaps you have another property that is clashing or something like that.
leppie
+3  A: 

In my experience Linq To SQL requires the Primary/Foreign key relationships established in the DB. Otherwise, you'll have to do a join.

Not sure if this applies to your situation, but it may...

http://stackoverflow.com/questions/619231/linq-to-sql-without-explicit-foreign-key-relationships

UPDATE:

It appears that you can get what you're looking for without establishing the Primary/Foreign key relationships in the database. In the LinqToSQL designer set primary keys on both columns on each table. I also had to turn off Auto-Sync on Parent Table's column that I assigned as a primary key.

Auto-Sync is described here.. Instructs the common language runtime (CLR) to retrieve the value after an insert or update operation.

Link: http://msdn.microsoft.com/en-us/library/bb386971.aspx

madcolor
+1  A: 

We had this problem with views. We simply defined the keys in the DBML editor and the property was finally defined.

Patrick McElreavy