Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I use the auto-generated Linq-to-SQL entity classes in 'disconnected' mode?
    text
    copied!<p>Suppose I have an automatically-generated <code>Employee</code> class based on the <code>Employees</code> table in my database.</p> <p>Now suppose that I want to pass employee data to a <code>ShowAges</code> method that will print out name &amp; age for a list of employees. I'll retrieve the data for a given set of employees via a linq query, which will return me a set of <code>Employee</code> instances. I can then pass the <code>Employee</code> instances to the <code>ShowAges</code> method, which can access the <code>Name</code> &amp; <code>Age</code> fields to get the data it needs.</p> <p>However, because my <code>Employees</code> table has relationships with various other tables in my database, my <code>Employee</code> class also has a <code>Department</code> field, a <code>Manager</code> field, etc. that provide access to related records in those other tables. If the <code>ShowAges</code> method were to invoke any of those methods, this would cause lots more data to be fetched from the database, on-demand.</p> <p>I want to be sure that the <code>ShowAges</code> method only uses the data I have already fetched for it, but I really don't want to have to go to the trouble of defining a new class which replicates the <code>Employee</code> class but has fewer methods. (In my real-world scenario, the class would have to be considerably more complex than the <code>Employee</code> class described here; it would have several 'joined' classes that do need to be populated, and others that don't).</p> <p>Is there a way to 'switch off' or 'disconnect' the <code>Employees</code> instances so that an attempt to access any property or related object that's not already populated will raise an exception?</p> <p>If not, then I assume that since this must be a common requirement, there might be an already-established pattern for doing this sort of thing?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload