Is there anyway simple ways to add a property to Linq to Sql generated entity to reference its DataContext? For example:
var myContext = new DataContext();
var product = context.Products.Where(p => p.Id == productId).SingleOrDefault();
and product entity has a property called "Context" (product.Context) that has a reference to the myContext, datacontext.
I know how to customize generated entities. My question is how to customize (i think DataContext) to set 'Context' property of each instance that it creates to itself.
I'm not sure I'm doing the right thing or not. I want to write a business encapsulation model that has best performance with less code. As i googled around I have find out that the DataContext object is very lightweight and there for I thought it would be a good way to add an instance of DataContext to each object. This will reduce the need to attach, detached objects again to a new instance of datacontext every time I want to update or delete them.
If you have any other solution I will really appreciate it.
Thanks