Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you don't want to manually maintain those DataLoadOptions, you could use the <a href="http://t4toolbox.codeplex.com" rel="nofollow">T4 Toolbox</a> to generate your L2S classes and customize the DataContext generator to build a DataLoadOptions property that you can assign to the DataContext LoadOptions property when you need it. That's what I did, and now, when I want to XML Serialize an object and all of it's descendants, I can.</p> <p>I added this code to the LinqToSqlDataContextTemplate.tt</p> <pre><code> /// &lt;summary&gt; /// Sets up a property that will allow loading of all child properties. /// This is done to make serializing and entire object graph easier. /// &lt;/summary&gt; private void SetupChildLoading() { #&gt; private DataLoadOptions loadAllChildrenOptions; public DataLoadOptions LoadAllChildrenOptions { get { if (loadAllChildrenOptions == null) { loadAllChildrenOptions = new DataLoadOptions(); &lt;#+ this.PushIndent(" "); foreach (Table t in this.Database.Table) { for (int i = 0; i &lt; t.Type.Items.Length; i++) { Association association = t.Type.Items[i] as Association; if (association != null) { if (association.AccessModifier == GeneratedTextTransformation.AccessModifier.Public &amp;&amp; !association.IsForeignKey) { this.WriteLine("loadAllChildrenOptions.LoadWith&lt;{0}&gt;(Q =&gt; Q.{1});",t.Type.Name.ToString(),association.Member); } } } } this.PopIndent(); #&gt; } return loadAllChildrenOptions; } } &lt;#+ } </code></pre> <p>And in the TransformText method:</p> <pre><code> #region LoadOptions &lt;#+ SetupChildLoading(); #&gt; #endregion </code></pre>
 

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