I am using Linq-to-SQL (C# 3.5) to read two tables, house and county, from my database (SQL Server 2000). House has a CountyID column that matches an ID column in the county table. The County table has ID and CountyName columns.There is no association in the database – I added it in the dbml file. (Parent class = County, Child class = House)
Now I can query the House table and get the county name as house.County.CountyName – just what I want.
This works great unless I set EnableObjectTracking false. I get approx 3X performance improvement but the County child object in House is null.
Is there a way around this?
When you set EnableObjectTracking to false, you also turn off lazy loading child entities as you have noticed. MSDN says…
You can use the
LoadWithmethod to populate your child entities if you want to keep Object Tracking Disabled. Please see MSDN for more information on the LoadWith