You add the following method to an application that uses LINQ to SQL:
public Person LookupStudent(intstudentId)
using (var dataContext = new SchoolDataClassesDataContext())
return dataContext.Persons.FirstOrDefault(p =>p.PersonID == studentId);
You find that the following code throws an exception when attempting to iterate the child entities given by the StudentGrades property:
var student = LookupStudent(studentId);
foreach (var g in student.StudentGrades)
You need to modify the LookupStudent method to fix the exception.
What should you do?

 Posted by Rajkatie on 8/31/2012 | Category: ADO.NET Interview questions | Views: 884 | Points: 40
Select from following answers:
  1. Create the DataContext without a using statement and do not call Dispose.
  2. Set the DataContextObjectTrackingEnabled property to False.
  3. Set the DataContextDeferredLoadingEnabled property to False.
  4. All Above

Show Correct Answer

Source: | | Alert Moderator 

Comments or Responses

Login to post response