Alex Rivera | Logout

Access LINQ-2-SQL DataContext in entity class

Asked 2008-12-15T16:31:25.227
9

Is there any simple way to access the DataContext in a linq2sql entity class.

I'm trying to create something like EntitySet but I cannot figure out how the EntitySet has access to the context that created the entity object in the first place.

I want to have a regular linq2sql entity class with a way for the class to access the DataContext that created it. I know it's possible because when you have an entity class with a primary key linq2sql gives you the option to load all children without creating a new DataContext.

Edit
Report

1 Answer

1

An Entity class should not be aware of the data context as its just a mapping of the table but the data context has the knowledge of all the entities and the connection properties

You are able to link to the child table through the parent entity class because of the entity relationship and not through the data context

The data context class will be used at the end where the entities are consumed, I don't see a need for the entities to be aware of the context,

If you can tell the specific scenario we can try another approach.

answered 2009-04-05T06:10:07.940

Your Answer