Accessing non-related entities in LinqToSql entity classes

Posted by Chris Johnson on Stack Overflow See other posts from Stack Overflow or by Chris Johnson
Published on 2012-06-29T05:33:27Z Indexed on 2012/06/30 9:16 UTC
Read the original article Hit count: 237

Filed under:
|
|

In LinqToSql, if I want to access a non-related entity in an entity partial class, how do I do this without creating a new DataContext?

Here's the scenario:

I have the tables Client, IssueType and ClientIssueType. A Client may specify a list of IssueTypes if they do not want to use the default IssueTypes. I have the default IssueTypes in the ClientIssueType table with a ClientId of null.

In my Client partial I'd like to try to retrieve all IssueTypes, and if none are found, return all default IssueTypes. The only way I can see of accessing the IssueTypes with a null ClientId is by accessing the table through a new DataContext, which is problematic once I want to start assigning them to Issues.

Where am I going wrong?

© Stack Overflow or respective owner

Related posts about linq-to-sql

Related posts about entity