When is the ‘unit of work’ no longer a ‘unit’? Which scenario is better on resources? THe first creates one connection wheras the second creates 4.
using (DataContext dc=new DataContext) { var orders= from o in dc.orders select ( new Product { property a= from a in ..join... select x, property b= from b in ..join... select y, property c= from c in ..join... select z.} ) }
OR
using (DataContext dc=new DataContext) { var orders= from o in dc.orders select ( new Product { property a = GetPropertyA(), property b = GetPropertyB(), property c = GetPropertyC()} ) }
When using LINQ if you add one entity to another and they use a different data context you are going to get an error. I would suggest keeping the same data context for each unit of work you are using. You can easily identify the unit of work you are processing by using the repository pattern to write your data access classes. If you’re not clear on the repository pattern, check out this entry