C# – LINQ to SQL – Problem with 1-to-1 association

clinqlinq-to-sqlooporm

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.

Best Answer

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...

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