<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>artiso Blog - LINQ</title>
    <link>http://www.artiso.com/ProBlog/</link>
    <description>Neues rund um's Thema .Net</description>
    <language>de-de</language>
    <copyright>Thomas</copyright>
    <lastBuildDate>Wed, 18 Jun 2008 15:47:17 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 1.9.6264.0</generator>
    <managingEditor>tschissler@artiso.com</managingEditor>
    <webMaster>tschissler@artiso.com</webMaster>
    <item>
      <trackback:ping>http://www.artiso.com/ProBlog/Trackback.aspx?guid=4b4fdca2-8193-4050-bb7c-af3d9ff7f338</trackback:ping>
      <pingback:server>http://www.artiso.com/ProBlog/pingback.aspx</pingback:server>
      <pingback:target>http://www.artiso.com/ProBlog/PermaLink,guid,4b4fdca2-8193-4050-bb7c-af3d9ff7f338.aspx</pingback:target>
      <dc:creator>Thomas Schissler</dc:creator>
      <wfw:comment>http://www.artiso.com/ProBlog/CommentView,guid,4b4fdca2-8193-4050-bb7c-af3d9ff7f338.aspx</wfw:comment>
      <wfw:commentRss>http://www.artiso.com/ProBlog/SyndicationService.asmx/GetEntryCommentsRss?guid=4b4fdca2-8193-4050-bb7c-af3d9ff7f338</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In einem Projekt nutze ich Contains um eine Liste mit IDs zu übergeben, um dann Objekte
per LINQtoSQL aus der Datenbank zu lesen. Das klappt wunderbar, solange die Liste
mit den IDs nicht zu groß wird. Bei knapp über 1000 IDs hatte ich allerdings ca. 5
Sek. für die Ausführung was mir dann doch recht lange vorkam. Ich habe mir dann mal
mit dem SQL Profiler angeschaut, was LINQ da eigentlich treibt und hatte dann schnell
eine Vermutung. LINQtoSQL ruft an der stellen nämlich eine Stored Procedure auf und
übergibt die IDs als Parameter dort hin, d.h. über 1000 Parameter deklarieren und
zuweisen, das könnte dauern. Ich habe das Statement dann testhalber einfach umgebaut,
dass ich im SELECT direkt die IDs über ein IN(...) angab und siehe da, diese Abfrage
war nun um Dimensionen schneller.
</p>
        <p>
Merke: Über Contains keine große Anzahl von Parametern übergeben, statt dessen lieber
die Abfrage selber mit einem IN aufbauen.
</p>
        <img width="0" height="0" src="http://www.artiso.com/ProBlog/aggbug.ashx?id=4b4fdca2-8193-4050-bb7c-af3d9ff7f338" />
      </body>
      <title>Ung&amp;uuml;nstige Performance bei Contains in LINQtoSQL</title>
      <guid isPermaLink="false">http://www.artiso.com/ProBlog/PermaLink,guid,4b4fdca2-8193-4050-bb7c-af3d9ff7f338.aspx</guid>
      <link>http://www.artiso.com/ProBlog/PermaLink,guid,4b4fdca2-8193-4050-bb7c-af3d9ff7f338.aspx</link>
      <pubDate>Wed, 18 Jun 2008 15:47:17 GMT</pubDate>
      <description>&lt;p&gt;
In einem Projekt nutze ich Contains um eine Liste mit IDs zu übergeben, um dann Objekte
per LINQtoSQL aus der Datenbank zu lesen. Das klappt wunderbar, solange die Liste
mit den IDs nicht zu groß wird. Bei knapp über 1000 IDs hatte ich allerdings ca. 5
Sek. für die Ausführung was mir dann doch recht lange vorkam. Ich habe mir dann mal
mit dem SQL Profiler angeschaut, was LINQ da eigentlich treibt und hatte dann schnell
eine Vermutung. LINQtoSQL ruft an der stellen nämlich eine Stored Procedure auf und
übergibt die IDs als Parameter dort hin, d.h. über 1000 Parameter deklarieren und
zuweisen, das könnte dauern. Ich habe das Statement dann testhalber einfach umgebaut,
dass ich im SELECT direkt die IDs über ein IN(...) angab und siehe da, diese Abfrage
war nun um Dimensionen schneller.
&lt;/p&gt;
&lt;p&gt;
Merke: Über Contains keine große Anzahl von Parametern übergeben, statt dessen lieber
die Abfrage selber mit einem IN aufbauen.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.artiso.com/ProBlog/aggbug.ashx?id=4b4fdca2-8193-4050-bb7c-af3d9ff7f338" /&gt;</description>
      <comments>http://www.artiso.com/ProBlog/CommentView,guid,4b4fdca2-8193-4050-bb7c-af3d9ff7f338.aspx</comments>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.artiso.com/ProBlog/Trackback.aspx?guid=543d6b5e-51df-42ef-9489-039731e0bff4</trackback:ping>
      <pingback:server>http://www.artiso.com/ProBlog/pingback.aspx</pingback:server>
      <pingback:target>http://www.artiso.com/ProBlog/PermaLink,guid,543d6b5e-51df-42ef-9489-039731e0bff4.aspx</pingback:target>
      <dc:creator>Thomas Schissler</dc:creator>
      <wfw:comment>http://www.artiso.com/ProBlog/CommentView,guid,543d6b5e-51df-42ef-9489-039731e0bff4.aspx</wfw:comment>
      <wfw:commentRss>http://www.artiso.com/ProBlog/SyndicationService.asmx/GetEntryCommentsRss?guid=543d6b5e-51df-42ef-9489-039731e0bff4</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Ich habe bei mir eine Liste die wiederum eine Liste mit Unterobjekten enthält. Ich
möchte nun daraus ein Element der Unterliste mit einer bestimmten ID selektieren.
Eine klare Sache für LINQ!
</p>
        <p>
Als Leitfaden habe ich auf 101 LINQ Samples mir folgendes Beispiel rausgesucht:
</p>
        <div>
          <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 1:</span>
              <span style="color: #0000ff">public</span>
              <span style="color: #0000ff">void</span> Linq15()
{</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 2:</span> List
customers = GetCustomerList();</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 3:</span>  </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 4:</span> var
orders =</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 5:</span> from
c <span style="color: #0000ff">in</span> customers,</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 6:</span> o <span style="color: #0000ff">in</span> c.Orders</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 7:</span>
              <span style="color: #0000ff">where</span> o.Total
&lt; 500.00M</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 8:</span> select <span style="color: #0000ff">new</span> {c.CustomerID,
o.OrderID, o.Total};</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 9:</span>  </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 10:</span> ObjectDumper.Write(orders);</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 11:</span> }</pre>
          </div>
        </div>
        <p>
 
</p>
        <p>
Das sieht ganz eifach aus, hat bei mir aber absolut nicht funktioniert. Ich konnte
das schon nicht sauber eingeben, da er in Zeile 6 für c keine Intellisense-Unterstützung
geboten hat. Das Ganze konnte ich dann lösen, indem ich das etwas umgestellt habe,
auf das Beispiel oben übertragen sieht meine Lösung so aus:
</p>
        <div>
          <div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 1:</span>
              <span style="color: #0000ff">public</span>
              <span style="color: #0000ff">void</span> Linq15()
{</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 2:</span> List
customers = GetCustomerList();</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 3:</span>  </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 4:</span> var
orders =</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 5:</span> from
c <span style="color: #0000ff">in</span> customers</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 6:</span>
              <strong>from</strong> o <span style="color: #0000ff">in</span> c.Orders</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 7:</span>
              <span style="color: #0000ff">where</span> o.Total
&lt; 500.00M</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 8:</span> select <span style="color: #0000ff">new</span> {c.CustomerID,
o.OrderID, o.Total};</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 9:</span>  </pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 10:</span> ObjectDumper.Write(orders);</pre>
            <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
              <span style="color: #606060"> 11:</span> }</pre>
          </div>
        </div>
        <p>
 
</p>
        <p>
Ich habe einfach in Zeile 6 statt des Kommas in der vorherigen Zeile nochmals ein
from eingebaut. So funktioniert es bei mir nun, wie ich mir das gewünscht habe.
</p>
        <img width="0" height="0" src="http://www.artiso.com/ProBlog/aggbug.ashx?id=543d6b5e-51df-42ef-9489-039731e0bff4" />
      </body>
      <title>Verkn&amp;uuml;pfte Abfragen mit LINQ</title>
      <guid isPermaLink="false">http://www.artiso.com/ProBlog/PermaLink,guid,543d6b5e-51df-42ef-9489-039731e0bff4.aspx</guid>
      <link>http://www.artiso.com/ProBlog/PermaLink,guid,543d6b5e-51df-42ef-9489-039731e0bff4.aspx</link>
      <pubDate>Fri, 16 Nov 2007 16:57:01 GMT</pubDate>
      <description>&lt;p&gt;
Ich habe bei mir eine Liste die wiederum eine Liste mit Unterobjekten enthält. Ich
möchte nun daraus ein Element der Unterliste mit einer bestimmten ID selektieren.
Eine klare Sache für LINQ!
&lt;/p&gt;
&lt;p&gt;
Als Leitfaden habe ich auf 101 LINQ Samples mir folgendes Beispiel rausgesucht:
&lt;/p&gt;
&lt;div&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Linq15()
{&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 2:&lt;/span&gt; List
customers = GetCustomerList();&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 3:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 4:&lt;/span&gt; var
orders =&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 5:&lt;/span&gt; from
c &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; customers,&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 6:&lt;/span&gt; o &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; c.Orders&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 7:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; o.Total
&amp;lt; 500.00M&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 8:&lt;/span&gt; select &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; {c.CustomerID,
o.OrderID, o.Total};&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 9:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 10:&lt;/span&gt; ObjectDumper.Write(orders);&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 11:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Das sieht ganz eifach aus, hat bei mir aber absolut nicht funktioniert. Ich konnte
das schon nicht sauber eingeben, da er in Zeile 6 für c keine Intellisense-Unterstützung
geboten hat. Das Ganze konnte ich dann lösen, indem ich das etwas umgestellt habe,
auf das Beispiel oben übertragen sieht meine Lösung so aus:
&lt;/p&gt;
&lt;div&gt;
&lt;div style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 1:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Linq15()
{&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 2:&lt;/span&gt; List
customers = GetCustomerList();&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 3:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 4:&lt;/span&gt; var
orders =&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 5:&lt;/span&gt; from
c &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; customers&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 6:&lt;/span&gt; &lt;strong&gt;from&lt;/strong&gt; o &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; c.Orders&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 7:&lt;/span&gt; &lt;span style="color: #0000ff"&gt;where&lt;/span&gt; o.Total
&amp;lt; 500.00M&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 8:&lt;/span&gt; select &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; {c.CustomerID,
o.OrderID, o.Total};&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 9:&lt;/span&gt;&amp;nbsp; &lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 10:&lt;/span&gt; ObjectDumper.Write(orders);&lt;/pre&gt;
&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #606060"&gt; 11:&lt;/span&gt; }&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Ich habe einfach in Zeile 6 statt des Kommas in der vorherigen Zeile nochmals ein
from eingebaut. So funktioniert es bei mir nun, wie ich mir das gewünscht habe.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.artiso.com/ProBlog/aggbug.ashx?id=543d6b5e-51df-42ef-9489-039731e0bff4" /&gt;</description>
      <comments>http://www.artiso.com/ProBlog/CommentView,guid,543d6b5e-51df-42ef-9489-039731e0bff4.aspx</comments>
      <category>C# 3.0;LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.artiso.com/ProBlog/Trackback.aspx?guid=9fd35801-8ac7-466c-a5b5-4ba722ee6e76</trackback:ping>
      <pingback:server>http://www.artiso.com/ProBlog/pingback.aspx</pingback:server>
      <pingback:target>http://www.artiso.com/ProBlog/PermaLink,guid,9fd35801-8ac7-466c-a5b5-4ba722ee6e76.aspx</pingback:target>
      <dc:creator>Thomas Schissler</dc:creator>
      <wfw:comment>http://www.artiso.com/ProBlog/CommentView,guid,9fd35801-8ac7-466c-a5b5-4ba722ee6e76.aspx</wfw:comment>
      <wfw:commentRss>http://www.artiso.com/ProBlog/SyndicationService.asmx/GetEntryCommentsRss?guid=9fd35801-8ac7-466c-a5b5-4ba722ee6e76</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
LINQ erweitert ICollections, IEnumerable etc. mit einigen Extension Methods wie z.B.
ToList() was sehr hilfreich ist. Ich hatte gerade das Problem, dass diese Extensions
nicht im Intellisense angezeigt wurden. Nach einigem Suchen habe ich festgestellt,
das lag daren, dass ich kein using System.Linq drin hatte, sondern nur auf System.Data.Linq
und System.Data.Linq.Mapping. Nachdem ich das using ergänzt habe, funktionierte das
problemlos.
</p>
        <img width="0" height="0" src="http://www.artiso.com/ProBlog/aggbug.ashx?id=9fd35801-8ac7-466c-a5b5-4ba722ee6e76" />
      </body>
      <title>LINQ Extensions auf ICollections etc.</title>
      <guid isPermaLink="false">http://www.artiso.com/ProBlog/PermaLink,guid,9fd35801-8ac7-466c-a5b5-4ba722ee6e76.aspx</guid>
      <link>http://www.artiso.com/ProBlog/PermaLink,guid,9fd35801-8ac7-466c-a5b5-4ba722ee6e76.aspx</link>
      <pubDate>Mon, 12 Nov 2007 17:31:35 GMT</pubDate>
      <description>&lt;p&gt;
LINQ erweitert ICollections, IEnumerable etc. mit einigen Extension Methods wie z.B.
ToList() was sehr hilfreich ist. Ich hatte gerade das Problem, dass diese Extensions
nicht im Intellisense angezeigt wurden. Nach einigem Suchen habe ich festgestellt,
das lag daren, dass ich kein using System.Linq drin hatte, sondern nur auf System.Data.Linq
und System.Data.Linq.Mapping. Nachdem ich das using ergänzt habe, funktionierte das
problemlos.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.artiso.com/ProBlog/aggbug.ashx?id=9fd35801-8ac7-466c-a5b5-4ba722ee6e76" /&gt;</description>
      <comments>http://www.artiso.com/ProBlog/CommentView,guid,9fd35801-8ac7-466c-a5b5-4ba722ee6e76.aspx</comments>
      <category>C# 3.0;LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.artiso.com/ProBlog/Trackback.aspx?guid=a9034ca2-7aac-4acd-be7a-b63e2c47183b</trackback:ping>
      <pingback:server>http://www.artiso.com/ProBlog/pingback.aspx</pingback:server>
      <pingback:target>http://www.artiso.com/ProBlog/PermaLink,guid,a9034ca2-7aac-4acd-be7a-b63e2c47183b.aspx</pingback:target>
      <dc:creator>Thomas Schissler</dc:creator>
      <wfw:comment>http://www.artiso.com/ProBlog/CommentView,guid,a9034ca2-7aac-4acd-be7a-b63e2c47183b.aspx</wfw:comment>
      <wfw:commentRss>http://www.artiso.com/ProBlog/SyndicationService.asmx/GetEntryCommentsRss?guid=a9034ca2-7aac-4acd-be7a-b63e2c47183b</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Auf dieser Seite sind jede Menge Beispiele zum Thema LINQ thematisch geordnet
aufgelistet. Hier findet man wirklich für viele Einsatzgebiete entsprechende Beispiele.
Wirklich empfehlenswert! 
</p>
        <p>
          <a href="http://msdn2.microsoft.com/en-us/vcsharp/aa336746.aspx">101 LINQ Samples</a>
        </p>
        <img width="0" height="0" src="http://www.artiso.com/ProBlog/aggbug.ashx?id=a9034ca2-7aac-4acd-be7a-b63e2c47183b" />
      </body>
      <title>101 LINQ Samples</title>
      <guid isPermaLink="false">http://www.artiso.com/ProBlog/PermaLink,guid,a9034ca2-7aac-4acd-be7a-b63e2c47183b.aspx</guid>
      <link>http://www.artiso.com/ProBlog/PermaLink,guid,a9034ca2-7aac-4acd-be7a-b63e2c47183b.aspx</link>
      <pubDate>Thu, 25 Oct 2007 19:30:39 GMT</pubDate>
      <description>&lt;p&gt;
Auf dieser Seite sind jede Menge&amp;nbsp;Beispiele zum Thema LINQ thematisch geordnet
aufgelistet. Hier findet man wirklich für viele Einsatzgebiete entsprechende Beispiele.
Wirklich&amp;nbsp;empfehlenswert!&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://msdn2.microsoft.com/en-us/vcsharp/aa336746.aspx"&gt;101 LINQ Samples&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.artiso.com/ProBlog/aggbug.ashx?id=a9034ca2-7aac-4acd-be7a-b63e2c47183b" /&gt;</description>
      <comments>http://www.artiso.com/ProBlog/CommentView,guid,a9034ca2-7aac-4acd-be7a-b63e2c47183b.aspx</comments>
      <category>.Net 3.5;LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.artiso.com/ProBlog/Trackback.aspx?guid=dbf52623-b452-423f-b289-49929a9e4791</trackback:ping>
      <pingback:server>http://www.artiso.com/ProBlog/pingback.aspx</pingback:server>
      <pingback:target>http://www.artiso.com/ProBlog/PermaLink,guid,dbf52623-b452-423f-b289-49929a9e4791.aspx</pingback:target>
      <dc:creator>Thomas Schissler</dc:creator>
      <wfw:comment>http://www.artiso.com/ProBlog/CommentView,guid,dbf52623-b452-423f-b289-49929a9e4791.aspx</wfw:comment>
      <wfw:commentRss>http://www.artiso.com/ProBlog/SyndicationService.asmx/GetEntryCommentsRss?guid=dbf52623-b452-423f-b289-49929a9e4791</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Ich habe in einer Anwendung ein Objekt, das über ca. 30 List&lt;double&gt; Properties
verfügt. Dieses Objekt möchte ich nun mit LINQ to SQL in die Datenbank schreiben.
Natürlich unterstützt LINQ 1:n-Beziehungen in Objekten aber in der Datenbank müsste
ich dann für jedes List-Property eine eigene Tabelle anlegen und für jedes Property
einen eigenen Typ definieren. Das schien mir doch sehr umständlich.
</p>
        <p>
Ich habe dann nach einer Möglichkeit gesucht, die List-Elemente etwas effizieter zu
speichern, am einfachsten in einem Feld je Liste, da ich die für die Abfrage eh nicht
brauche. Aber wie kann ich die Ausgabe von LINQ in die Datenbank steuern? Wie kann
ich erreichen, dass LINQ meine Daten entsprechend formatiert?
</p>
        <p>
Googeln brachte keine vernünftigen Ergebnisse und sonst bin ich auch nicht fündig
geworden, aber dann kam die Idee (manchmal ist es schneller erst nachzudenken bevor
man googelt, aber das vergisst man oft ;-)). Die Grundidee war, für jede Liste noch
ein zusätzliches Property anlegen, das die Daten im Getter und Setter entsprechend
formatiert. Die Hoffnung war, wenn ich dieses Property mit einem Column-Attribut versehe,
wird LINQ den formatierten Inhalt schreiben und beim Lesen wieder zurückformatieren.
</p>
        <div>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <span style="color: #0000ff">public</span> List&lt;<span style="color: #0000ff">string</span>&gt;
Sales { get; set; } [Column(Name=<span style="color: #006080">"Sales"</span>, DbType
= <span style="color: #006080">"nvarchar(4000)"</span>)] <span style="color: #0000ff">private</span><span style="color: #0000ff">string</span> SalesString
{ get { <span style="color: #0000ff">return</span><span style="color: #0000ff">string</span>.Join(<span style="color: #006080">"|"</span>,
Sales.ToArray()); } set { <span style="color: #0000ff">if</span> (<span style="color: #0000ff">value</span> != <span style="color: #0000ff">null</span>)
Sales = <span style="color: #0000ff">value</span>.Split(<span style="color: #006080">'|'</span>).ToList();
} }</pre>
        </div>
        <p>
 
</p>
        <p>
Ich habe einfach eine Text-Spalte in der Datenbank verwendet und die einzelnen List-Elemente
mit einem Trennzeichen verbunden (der Einfachkeit halber habe ich mit einer List of
Strings gearbeitet. Für die Tests ist das ausreichend und sollte auf beliebige andere
Typen übertragbar sein). 
</p>
        <p>
Einen kleinen Stolperstein gibt es noch. Beim Ausführen erhielt ich folgende Meldung:
</p>
        <p>
          <a href="http://www.artiso.com/ProBlog/content/binary/WindowsLiveWriter/ListeneffizientspeichernmitLINQtoSQL_9E29/image.png" atomicselection="true">
            <img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="242" alt="image" src="http://www.artiso.com/ProBlog/content/binary/WindowsLiveWriter/ListeneffizientspeichernmitLINQtoSQL_9E29/image_thumb.png" width="431" border="0" />
          </a>
        </p>
        <p>
LINQ verwendet Optimistic Locking für das Schreiben und hat wohl Probleme, wenn der
Inhalt des Property im Getter verändert wird. Abhilfe schafft hier das zusätzliche
Attribut UpdateCheck, also sollte das Attribut zu dem Property so aussehen:
</p>
        <div>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">[Column(Name=<span style="color: #006080">"Sales"</span>,
DbType = <span style="color: #006080">"nvarchar(4000)"</span>, UpdateCheck=UpdateCheck.Never)]</pre>
        </div>
        <p>
 
</p>
        <p>
Hier sind natürlich auch noch andere Möglichkeiten der Datenrepräsentation möglich.
Hier mal ein Beispiel mit XML-Serialisierung und diesesmal auch mit Doubl-Werten.
</p>
        <div>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <span style="color: #0000ff">public</span> List&lt;<span style="color: #0000ff">double</span>&gt;
Sales { get; set; } [Column(Name=<span style="color: #006080">"Sales"</span>, DbType
= <span style="color: #006080">"xml"</span>, UpdateCheck=UpdateCheck.Never)] <span style="color: #0000ff">private</span><span style="color: #0000ff">string</span> SalesString
{ get { UTF8Encoding encoding = <span style="color: #0000ff">new</span> UTF8Encoding();
MemoryStream ms = <span style="color: #0000ff">new</span> MemoryStream(); XmlSerializer
xmlSer = <span style="color: #0000ff">new</span> XmlSerializer(<span style="color: #0000ff">typeof</span>(List&lt;<span style="color: #0000ff">double</span>&gt;));
xmlSer.Serialize(ms, Sales); <span style="color: #0000ff">return</span> encoding.GetString(ms.ToArray());
} set { <span style="color: #0000ff">if</span> (<span style="color: #0000ff">value</span> != <span style="color: #0000ff">null</span>)
{ UTF8Encoding encoding = <span style="color: #0000ff">new</span> UTF8Encoding();
MemoryStream ms = <span style="color: #0000ff">new</span> MemoryStream(encoding.GetBytes(<span style="color: #0000ff">value</span>));
XmlSerializer xmlSer = <span style="color: #0000ff">new</span> XmlSerializer(<span style="color: #0000ff">typeof</span>(List&lt;<span style="color: #0000ff">double</span>&gt;));
Sales = (List&lt;<span style="color: #0000ff">double</span>&gt;)xmlSer.Deserialize(ms);
} } }</pre>
        </div>
        <p>
 
</p>
        <p>
Dank an Bernhard Gojer für den Lösungsansatz.
</p>
        <img width="0" height="0" src="http://www.artiso.com/ProBlog/aggbug.ashx?id=dbf52623-b452-423f-b289-49929a9e4791" />
      </body>
      <title>Listen effizient speichern mit LINQ to SQL</title>
      <guid isPermaLink="false">http://www.artiso.com/ProBlog/PermaLink,guid,dbf52623-b452-423f-b289-49929a9e4791.aspx</guid>
      <link>http://www.artiso.com/ProBlog/PermaLink,guid,dbf52623-b452-423f-b289-49929a9e4791.aspx</link>
      <pubDate>Tue, 18 Sep 2007 10:09:29 GMT</pubDate>
      <description>&lt;p&gt;
Ich habe in einer Anwendung ein Objekt, das über ca. 30 List&amp;lt;double&amp;gt; Properties
verfügt. Dieses Objekt möchte ich nun mit LINQ to SQL in die Datenbank schreiben.
Natürlich unterstützt LINQ 1:n-Beziehungen in Objekten aber in der Datenbank müsste
ich dann für jedes List-Property eine eigene Tabelle anlegen und für jedes Property
einen eigenen Typ definieren. Das schien mir doch sehr umständlich.
&lt;/p&gt;
&lt;p&gt;
Ich habe dann nach einer Möglichkeit gesucht, die List-Elemente etwas effizieter zu
speichern, am einfachsten in einem Feld je Liste, da ich die für die Abfrage eh nicht
brauche. Aber wie kann ich die Ausgabe von LINQ in die Datenbank steuern? Wie kann
ich erreichen, dass LINQ meine Daten entsprechend formatiert?
&lt;/p&gt;
&lt;p&gt;
Googeln brachte keine vernünftigen Ergebnisse und sonst bin ich auch nicht fündig
geworden, aber dann kam die Idee (manchmal ist es schneller erst nachzudenken bevor
man googelt, aber das vergisst man oft ;-)). Die Grundidee war, für jede Liste noch
ein zusätzliches Property anlegen, das die Daten im Getter und Setter entsprechend
formatiert. Die Hoffnung war, wenn ich dieses Property mit einem Column-Attribut versehe,
wird LINQ den formatierten Inhalt schreiben und beim Lesen wieder zurückformatieren.
&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;
Sales { get; set; } [Column(Name=&lt;span style="color: #006080"&gt;"Sales"&lt;/span&gt;, DbType
= &lt;span style="color: #006080"&gt;"nvarchar(4000)"&lt;/span&gt;)] &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; SalesString
{ get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Join(&lt;span style="color: #006080"&gt;"|"&lt;/span&gt;,
Sales.ToArray()); } set { &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;value&lt;/span&gt; != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
Sales = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;.Split(&lt;span style="color: #006080"&gt;'|'&lt;/span&gt;).ToList();
} }&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Ich habe einfach eine Text-Spalte in der Datenbank verwendet und die einzelnen List-Elemente
mit einem Trennzeichen verbunden (der Einfachkeit halber habe ich mit einer List of
Strings gearbeitet. Für die Tests ist das ausreichend und sollte auf beliebige andere
Typen übertragbar sein). 
&lt;/p&gt;
&lt;p&gt;
Einen kleinen Stolperstein gibt es noch. Beim Ausführen erhielt ich folgende Meldung:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.artiso.com/ProBlog/content/binary/WindowsLiveWriter/ListeneffizientspeichernmitLINQtoSQL_9E29/image.png" atomicselection="true"&gt;&lt;img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="242" alt="image" src="http://www.artiso.com/ProBlog/content/binary/WindowsLiveWriter/ListeneffizientspeichernmitLINQtoSQL_9E29/image_thumb.png" width="431" border="0"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
LINQ verwendet Optimistic Locking für das Schreiben und hat wohl Probleme, wenn der
Inhalt&amp;nbsp;des&amp;nbsp;Property im Getter verändert wird. Abhilfe schafft hier das zusätzliche
Attribut UpdateCheck, also sollte das Attribut zu dem Property so aussehen:
&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;[Column(Name=&lt;span style="color: #006080"&gt;"Sales"&lt;/span&gt;,
DbType = &lt;span style="color: #006080"&gt;"nvarchar(4000)"&lt;/span&gt;, UpdateCheck=UpdateCheck.Never)]&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Hier sind natürlich auch noch andere Möglichkeiten der Datenrepräsentation möglich.
Hier mal ein Beispiel mit XML-Serialisierung und diesesmal auch mit Doubl-Werten.
&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;double&lt;/span&gt;&amp;gt;
Sales { get; set; } [Column(Name=&lt;span style="color: #006080"&gt;"Sales"&lt;/span&gt;, DbType
= &lt;span style="color: #006080"&gt;"xml"&lt;/span&gt;, UpdateCheck=UpdateCheck.Never)] &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; SalesString
{ get { UTF8Encoding encoding = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UTF8Encoding();
MemoryStream ms = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MemoryStream(); XmlSerializer
xmlSer = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XmlSerializer(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(List&amp;lt;&lt;span style="color: #0000ff"&gt;double&lt;/span&gt;&amp;gt;));
xmlSer.Serialize(ms, Sales); &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; encoding.GetString(ms.ToArray());
} set { &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;value&lt;/span&gt; != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
{ UTF8Encoding encoding = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UTF8Encoding();
MemoryStream ms = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; MemoryStream(encoding.GetBytes(&lt;span style="color: #0000ff"&gt;value&lt;/span&gt;));
XmlSerializer xmlSer = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XmlSerializer(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(List&amp;lt;&lt;span style="color: #0000ff"&gt;double&lt;/span&gt;&amp;gt;));
Sales = (List&amp;lt;&lt;span style="color: #0000ff"&gt;double&lt;/span&gt;&amp;gt;)xmlSer.Deserialize(ms);
} } }&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Dank an Bernhard Gojer für den Lösungsansatz.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.artiso.com/ProBlog/aggbug.ashx?id=dbf52623-b452-423f-b289-49929a9e4791" /&gt;</description>
      <comments>http://www.artiso.com/ProBlog/CommentView,guid,dbf52623-b452-423f-b289-49929a9e4791.aspx</comments>
      <category>.Net 3.5;LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.artiso.com/ProBlog/Trackback.aspx?guid=10ceccad-79c5-487e-88c0-3a46728f5838</trackback:ping>
      <pingback:server>http://www.artiso.com/ProBlog/pingback.aspx</pingback:server>
      <pingback:target>http://www.artiso.com/ProBlog/PermaLink,guid,10ceccad-79c5-487e-88c0-3a46728f5838.aspx</pingback:target>
      <dc:creator>Thomas Schissler</dc:creator>
      <wfw:comment>http://www.artiso.com/ProBlog/CommentView,guid,10ceccad-79c5-487e-88c0-3a46728f5838.aspx</wfw:comment>
      <wfw:commentRss>http://www.artiso.com/ProBlog/SyndicationService.asmx/GetEntryCommentsRss?guid=10ceccad-79c5-487e-88c0-3a46728f5838</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Nutzt man LINQ in einer klassischen 2-tier Anwendung, dann funktioniert das wunderbar.
Nur leider ist das eher ein Auslaufmodell. Bei modernen Anwendungen kommt häufig
ein 3-tier Ansatz vor (SOA etc.). An einer kleinen WCF-Anwendung möchti ich das Problem
kurz schildern:
</p>
        <p>
Eine kleine Anwendung soll Daten darstellen und bearbeiten können. nehmen wir einfach
mal eine Adress-Verwaltung. Die Anwendung soll service-orientiert augebaut sein, d.h.
es gibt einen zetralen Service, der die Schnittstelle zur Datenbank implementiert. 
</p>
        <p>
Soll nun eine Liste der Adressen geladen werden, ruft der Client auf dem Service eine
entsprechende Methode auf. Diese Methode nutzt nun LINQ um die Adressen aus der Datenbank
zu lesen und als List&lt;cAddress&gt; zurückzuliefern. Diese kann der Client nun darstellen.
So weit, so gut. Aber was passiert jetzt, wenn eine Adresse bearbeitet wird und diese
wieder gespeichert werden soll. Der Client ruft eine entsprechende Methode auf dem
Service auf und übergibt das neue Adress-Objekt. Durch die Übertragung zum Client
und wieder zurück muss das Objekt serialisiert und wieder deserialisiert werden. Dadurch
stellt es eine komplett andere Instanz dar, wenn es wieder beim Service ankommt und
hat daher keine Verbindung mehr zum DataContext (vorausgesetzt dieser wäre überhaupt
noch vorhanden, dazu müsste der in einer Session aufbewahrt werden, was recht problematisch
ist). Wie bekommt man nun das neue Adress-Objekt in die Datenbank?
</p>
        <p>
Die von Microsoft vorgschlagene Vorgehensweise geht über die Attach-Methode. Dabei
erzeugt man einfach einen neuen DataContext und fügt das bearbeitete Objekt diesem
hinzu. Das Problem dabei ist das Change-Tracking des DataContext. Dieser möchte nämlich
wissen, was sich an dem Objekt geändert hat. Führt man nur einen Attach durch, dann
bewirkt das gar nichts. Man kann entweder das gesamte Objekt als bearbeitet deklarieren,
so wie ich das in diesem <a href="http://www.artiso.com/ProBlog/PermaLink,guid,b0ff908d-bdf9-4937-aa10-74d266ff8709.aspx">Post</a> demonstriert
habe, oder man muss ein Referenz-Objekt mit angeben, gegen das das Objekt evrglichen
werden kann. Eine weitere Möglichkeit ist auch noch die Zuweisung aller geänderten
Eigenschaften nach dem Attach, da ab diesem Zeitpunkt das Change-Tracking alle Änderungen
registriert. Das ist alles nicht so schön.
</p>
        <p>
Mit einem kleinen Trick kan man sich hier die Sache etwas einfacher machen, auch wenn
das nicht gerade sauber ist. Man kann das Objekt einfach löschen und dann neu hinzufügen.
Das angenehme ist, dass der DataContext das recht intelligent handhabt und intern
aus dem Delete and Insert ein Update macht. Der Code sieht dann ungefähr so aus:
</p>
        <div>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">void</span> UpdateCompany(LINQTest.Contracts.DataContracts.cContactCompany
company) { cContactDataContext db = <span style="color: #0000ff">new</span> cContactDataContext(<span style="color: #006080">"Data
Source=NOTEBOOK_VISTA;Initial Catalog=LINQ;Persist Security Info=True;"</span>); cContactCompany
OrigCompany = db.Companies.Single&lt;cContactCompany&gt;(c =&gt; c.ID == company.ID); <span style="color: #0000ff">if</span> (OrigCompany
!= <span style="color: #0000ff">null</span>) { db.Companies.Remove(OrigCompany); }
db.Companies.Add(company); db.SubmitChanges(); }</pre>
        </div>
        <p>
 
</p>
        <p>
Auch wenn das, wie gesagt nicht besonders schön ist, ich konnte noch keine negativen
"Nebenwirkungen" feststellen, der Code macht genau das, was ich von ihm erwarte und
das auch noch mit relativ schönem SQL, wie mir der SQL-Profiler anzeigt. Erst wird
mal ein SELECT gemacht um zu sehen, ob das Element schon vorhanden ist (diesen Punkt
kann man sicher noch optimieren):
</p>
        <div>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <span style="color: #0000ff">exec</span> sp_executesql
N<span style="color: #006080">'SELECT [t0].[ID], [t0].[CompanyName], [t0].[CompanyAddress],
[t0].[CompanyTelephone] FROM [tblCompanies] AS [t0] WHERE [t0].[ID] = @p0'</span>,N<span style="color: #006080">'@p0
int'</span>,@p0=2</pre>
        </div>
        <p>
 
</p>
        <p>
Dann wird der Update ausgeführt
</p>
        <div>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <span style="color: #0000ff">exec</span> sp_executesql
N<span style="color: #006080">'UPDATE [tblCompanies] SET [CompanyName] = @p1 WHERE
[ID] = @p0'</span>,N<span style="color: #006080">'@p0 int,@p1 nvarchar(12)'</span>,@p0=2,@p1=N<span style="color: #006080">'Test-Company'</span></pre>
        </div>
        <p>
 
</p>
        <p>
Das sieht doch eigentlich sehr schön aus.
</p>
        <p>
Problematisch wird die Sache nun, wenn das Objekt Unterelemente enthält, also z.B.
Ansprechpartner. Hier gibt es mit dem Attach keine saubere Lösung undauch der Delete
and Insert Ansatz versagt hier zunächst. Es wird einfach für alle untergeordneten
Elemente ein Insert ausgeführt, egal ob diese bereits existieren oder nicht. Das Ganze
kann man lösen, indem man auch die Unterelemente zunächst löscht. 
</p>
        <div>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">void</span> UpdateCompany(LINQTest.Contracts.DataContracts.cContactCompany
company) { cContactDataContext db = <span style="color: #0000ff">new</span> cContactDataContext(<span style="color: #006080">"Data
Source=NOTEBOOK_VISTA;Initial Catalog=LINQ;Persist Security Info=True;User ID=sa;Password=admin"</span>);
cContactCompany OrigCompany = db.Companies.Single&lt;cContactCompany&gt;(c =&gt; c.ID
== company.ID); <span style="color: #0000ff">if</span> (OrigCompany != <span style="color: #0000ff">null</span>)
{ db.Companies.Remove(OrigCompany); <span style="color: #0000ff">foreach</span> (cContactPerson
p <span style="color: #0000ff">in</span> OrigCompany.Persons) { db.Persons.Remove(p);
} } db.Companies.Add(company); db.SubmitChanges(); }</pre>
        </div>
        <p>
 
</p>
        <p>
Auch hier wird wieder ein schönes Update daraus gebaut. 
</p>
        <p>
Also so richtig toll finde ich das Ganze noch nicht. Hier bleibt zu hoffen, dass Microsoft
an dieser Stelle schnellstens noch nachbessert. Das sieht im Moment aber eher schlecht
aus, wie man <a href="http://oakleafblog.blogspot.com/2007/05/changes-coming-to-linq-for-sql.html" target="_blank">hier</a> und <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1747638&amp;SiteID=1" target="_blank">hier</a> lesen
kann. Vielleicht hat schon jemand von euch hier Erfahrungen gesammelt. Über einen
Kommentar würde ich mich freuen, auch über "Bedenken" bezgl. des Delete and Insert
Ansatzes. 
</p>
        <img width="0" height="0" src="http://www.artiso.com/ProBlog/aggbug.ashx?id=10ceccad-79c5-487e-88c0-3a46728f5838" />
      </body>
      <title>LINQ DataContext in Unconnected Szenarien</title>
      <guid isPermaLink="false">http://www.artiso.com/ProBlog/PermaLink,guid,10ceccad-79c5-487e-88c0-3a46728f5838.aspx</guid>
      <link>http://www.artiso.com/ProBlog/PermaLink,guid,10ceccad-79c5-487e-88c0-3a46728f5838.aspx</link>
      <pubDate>Mon, 17 Sep 2007 18:27:14 GMT</pubDate>
      <description>&lt;p&gt;
Nutzt man LINQ in einer klassischen 2-tier Anwendung, dann funktioniert das wunderbar.
Nur leider ist das eher ein Auslaufmodell.&amp;nbsp;Bei modernen Anwendungen kommt häufig
ein 3-tier Ansatz vor (SOA etc.). An einer kleinen WCF-Anwendung möchti ich das Problem
kurz schildern:
&lt;/p&gt;
&lt;p&gt;
Eine kleine Anwendung soll Daten darstellen und bearbeiten können. nehmen wir einfach
mal eine Adress-Verwaltung. Die Anwendung soll service-orientiert augebaut sein, d.h.
es gibt einen zetralen Service, der die Schnittstelle zur Datenbank implementiert. 
&lt;/p&gt;
&lt;p&gt;
Soll nun eine Liste der Adressen geladen werden, ruft der Client auf dem Service eine
entsprechende Methode auf. Diese Methode nutzt nun LINQ um die Adressen aus der Datenbank
zu lesen und als List&amp;lt;cAddress&amp;gt; zurückzuliefern. Diese kann der Client nun darstellen.
So weit, so gut. Aber was passiert jetzt, wenn eine Adresse bearbeitet wird und diese
wieder gespeichert werden soll. Der Client ruft eine entsprechende Methode auf dem
Service auf und übergibt das neue Adress-Objekt. Durch die Übertragung zum Client
und wieder zurück muss das Objekt serialisiert und wieder deserialisiert werden. Dadurch
stellt es eine komplett andere Instanz dar, wenn es wieder beim Service ankommt und
hat daher keine Verbindung mehr zum DataContext (vorausgesetzt dieser wäre überhaupt
noch vorhanden, dazu müsste der in einer Session aufbewahrt werden, was recht problematisch
ist). Wie bekommt man nun das neue Adress-Objekt in die Datenbank?
&lt;/p&gt;
&lt;p&gt;
Die von Microsoft vorgschlagene Vorgehensweise geht über die Attach-Methode. Dabei
erzeugt man einfach einen neuen DataContext und fügt das bearbeitete Objekt diesem
hinzu. Das Problem dabei ist das Change-Tracking des DataContext. Dieser möchte nämlich
wissen, was sich an dem Objekt geändert hat. Führt man nur einen Attach durch, dann
bewirkt das gar nichts. Man kann entweder das gesamte Objekt als bearbeitet deklarieren,
so wie ich das in diesem &lt;a href="http://www.artiso.com/ProBlog/PermaLink,guid,b0ff908d-bdf9-4937-aa10-74d266ff8709.aspx"&gt;Post&lt;/a&gt; demonstriert
habe, oder man muss ein Referenz-Objekt mit angeben, gegen das das Objekt evrglichen
werden kann. Eine weitere Möglichkeit ist auch noch die Zuweisung aller geänderten
Eigenschaften nach dem Attach, da ab diesem Zeitpunkt das Change-Tracking alle Änderungen
registriert. Das ist alles nicht so schön.
&lt;/p&gt;
&lt;p&gt;
Mit einem kleinen Trick kan man sich hier die Sache etwas einfacher machen, auch wenn
das nicht gerade sauber ist. Man kann das Objekt einfach löschen und dann neu hinzufügen.
Das angenehme ist, dass der DataContext das recht intelligent handhabt und intern
aus dem Delete and Insert ein Update macht. Der Code sieht dann ungefähr so aus:
&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; UpdateCompany(LINQTest.Contracts.DataContracts.cContactCompany
company) { cContactDataContext db = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; cContactDataContext(&lt;span style="color: #006080"&gt;"Data
Source=NOTEBOOK_VISTA;Initial Catalog=LINQ;Persist Security Info=True;"&lt;/span&gt;); cContactCompany
OrigCompany = db.Companies.Single&amp;lt;cContactCompany&amp;gt;(c =&amp;gt; c.ID == company.ID); &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (OrigCompany
!= &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;) { db.Companies.Remove(OrigCompany); }
db.Companies.Add(company); db.SubmitChanges(); }&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Auch wenn das, wie gesagt nicht besonders schön ist, ich konnte noch keine negativen
"Nebenwirkungen" feststellen, der Code macht genau das, was ich von ihm erwarte und
das auch noch mit relativ schönem SQL, wie mir der SQL-Profiler anzeigt. Erst wird
mal ein SELECT gemacht um zu sehen, ob das Element schon vorhanden ist (diesen Punkt
kann man sicher noch optimieren):
&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;exec&lt;/span&gt; sp_executesql
N&lt;span style="color: #006080"&gt;'SELECT [t0].[ID], [t0].[CompanyName], [t0].[CompanyAddress],
[t0].[CompanyTelephone] FROM [tblCompanies] AS [t0] WHERE [t0].[ID] = @p0'&lt;/span&gt;,N&lt;span style="color: #006080"&gt;'@p0
int'&lt;/span&gt;,@p0=2&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Dann wird der Update ausgeführt
&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;exec&lt;/span&gt; sp_executesql
N&lt;span style="color: #006080"&gt;'UPDATE [tblCompanies] SET [CompanyName] = @p1 WHERE
[ID] = @p0'&lt;/span&gt;,N&lt;span style="color: #006080"&gt;'@p0 int,@p1 nvarchar(12)'&lt;/span&gt;,@p0=2,@p1=N&lt;span style="color: #006080"&gt;'Test-Company'&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Das sieht doch eigentlich sehr schön aus.
&lt;/p&gt;
&lt;p&gt;
Problematisch wird die Sache nun, wenn das Objekt Unterelemente enthält, also z.B.
Ansprechpartner. Hier gibt es mit dem Attach keine saubere Lösung undauch der Delete
and Insert Ansatz versagt hier zunächst. Es wird einfach für alle untergeordneten
Elemente ein Insert ausgeführt, egal ob diese bereits existieren oder nicht. Das Ganze
kann man lösen, indem man auch die Unterelemente zunächst löscht. 
&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; UpdateCompany(LINQTest.Contracts.DataContracts.cContactCompany
company) { cContactDataContext db = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; cContactDataContext(&lt;span style="color: #006080"&gt;"Data
Source=NOTEBOOK_VISTA;Initial Catalog=LINQ;Persist Security Info=True;User ID=sa;Password=admin"&lt;/span&gt;);
cContactCompany OrigCompany = db.Companies.Single&amp;lt;cContactCompany&amp;gt;(c =&amp;gt; c.ID
== company.ID); &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (OrigCompany != &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
{ db.Companies.Remove(OrigCompany); &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (cContactPerson
p &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; OrigCompany.Persons) { db.Persons.Remove(p);
} } db.Companies.Add(company); db.SubmitChanges(); }&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Auch hier wird wieder ein schönes Update daraus gebaut. 
&lt;/p&gt;
&lt;p&gt;
Also so richtig toll finde ich das Ganze noch nicht. Hier bleibt zu hoffen, dass Microsoft
an dieser Stelle schnellstens noch nachbessert. Das sieht im Moment aber eher schlecht
aus, wie man &lt;a href="http://oakleafblog.blogspot.com/2007/05/changes-coming-to-linq-for-sql.html" target="_blank"&gt;hier&lt;/a&gt;&amp;nbsp;und &lt;a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1747638&amp;amp;SiteID=1" target="_blank"&gt;hier&lt;/a&gt;&amp;nbsp;lesen
kann. Vielleicht hat schon jemand&amp;nbsp;von euch hier Erfahrungen gesammelt. Über einen
Kommentar würde ich mich freuen, auch über "Bedenken" bezgl. des Delete and Insert
Ansatzes.&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.artiso.com/ProBlog/aggbug.ashx?id=10ceccad-79c5-487e-88c0-3a46728f5838" /&gt;</description>
      <comments>http://www.artiso.com/ProBlog/CommentView,guid,10ceccad-79c5-487e-88c0-3a46728f5838.aspx</comments>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.artiso.com/ProBlog/Trackback.aspx?guid=b0ff908d-bdf9-4937-aa10-74d266ff8709</trackback:ping>
      <pingback:server>http://www.artiso.com/ProBlog/pingback.aspx</pingback:server>
      <pingback:target>http://www.artiso.com/ProBlog/PermaLink,guid,b0ff908d-bdf9-4937-aa10-74d266ff8709.aspx</pingback:target>
      <dc:creator>Thomas Schissler</dc:creator>
      <wfw:comment>http://www.artiso.com/ProBlog/CommentView,guid,b0ff908d-bdf9-4937-aa10-74d266ff8709.aspx</wfw:comment>
      <wfw:commentRss>http://www.artiso.com/ProBlog/SyndicationService.asmx/GetEntryCommentsRss?guid=b0ff908d-bdf9-4937-aa10-74d266ff8709</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Wie man an meinen letzten Posts sieht, beschäftige ich mich momentan sehr intensiv
mit LINQ to SQL. Eine wichtige Lektion habe ich gerade eben gelernt. Folgende Ausgangssituation:
</p>
        <p>
Ich habe eine ASP.Net Anwendung. In einem DAL lese ich per LINQ ein Objekt aus der
Datenbank und schreibe das dann in eine Session-Variable. Der Anwender bekommt das
Objekt an der Oberfläche angezeigt und kann es verändern. Nun möchte ich das Objekt
wieder in die Datenbank zurückschreiben. Fast alle Tutorials zu LINQ beschreiben,
wie einfach es ist, Daten via LINQ zu schreiben. Aber dort wird in einer einzigen
Funktion erst gelesen, dann werden die Daten verändert und dann wieder zurückgeschrieben.
Das tritt ja aber in der Praxis eher selten auf.
</p>
        <p>
Also habe ich mich gefragt, was LINQ tut, wenn ich den DataContext einfach neu instanziere
und dann einfach mein Objekt per Add an die Tabelle hinzufüge. Na ja,wie zu erwarten,
hat LINQ gemeldet, dass der entsprechende Primary Key bereits existiert. Also was
tun? Den gesamten DataContext in die Session legen? Dass das keine gute Idee ist,
habe ich ziemlich schnell rausgefunden. Der DataContext skaliert sehr schlecht, da
er ein eingebautes Change-Tracking, Identity Tracking und sonst noch ein paar Nettigkeiten
hat, die sich aber in einer Web_Anwendung recht eklig verhalten können.
</p>
        <p>
Nach einigem Suchen bin ich dann drauf gekommen, dass es auch noch eine Attach-Methode
gibt. Damit konnte ich mein Problem schön lösen. Das Ergebnis für das Schreiben sieht
nun so aus:
</p>
        <div>
          <pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">
            <span style="color: #0000ff">public</span>
            <span style="color: #0000ff">void</span> SaveProductVersion(cProductVersion
_ProductVersion) { DataContext dataContextProducts = <span style="color: #0000ff">new</span> DataContext(<span style="color: #006080">"Data
Source=NOTEBOOK_VISTA;Initial Catalog=ValuePlanner_2008;Integrated Security=True"</span>); <span style="color: #0000ff">if</span> (_ProductVersion.ID
== 0) { dataContextProducts.GetTable&lt;cProductVersion&gt;().Add(_ProductVersion);
} <span style="color: #0000ff">else</span> { dataContextProducts.GetTable&lt;cProductVersion&gt;().Attach(_ProductVersion,
true); } dataContextProducts.SubmitChanges(); }</pre>
        </div>
        <p>
 
</p>
        <p>
Hier wird abgefragt, ob es eine neue Produktversion ist (ID == 0). Wenn ja, dann füge
ich die per Add hinzu (die ID wird von LINQ automatisch vergeben). Bei einem bestehenden
Projekt verwende ich die Attach-Methode. Ganz einfach, wenn mans weiss. Wichtig ist
noch, dass alle Properties des Objektes das Attribut UpdateCheck=none benötigen.
</p>
        <img width="0" height="0" src="http://www.artiso.com/ProBlog/aggbug.ashx?id=b0ff908d-bdf9-4937-aa10-74d266ff8709" />
      </body>
      <title>LINQ to SQL in ASP.Net Anwendungen</title>
      <guid isPermaLink="false">http://www.artiso.com/ProBlog/PermaLink,guid,b0ff908d-bdf9-4937-aa10-74d266ff8709.aspx</guid>
      <link>http://www.artiso.com/ProBlog/PermaLink,guid,b0ff908d-bdf9-4937-aa10-74d266ff8709.aspx</link>
      <pubDate>Fri, 17 Aug 2007 06:53:05 GMT</pubDate>
      <description>&lt;p&gt;
Wie man an meinen letzten Posts sieht, beschäftige ich mich momentan sehr intensiv
mit LINQ to SQL. Eine wichtige Lektion habe ich gerade eben gelernt. Folgende Ausgangssituation:
&lt;/p&gt;
&lt;p&gt;
Ich habe eine ASP.Net Anwendung. In einem DAL lese ich per LINQ ein Objekt aus der
Datenbank und schreibe das dann in eine Session-Variable. Der Anwender bekommt das
Objekt an der Oberfläche angezeigt und kann es verändern. Nun möchte ich das Objekt
wieder in die Datenbank zurückschreiben. Fast alle Tutorials zu LINQ beschreiben,
wie einfach es ist, Daten via LINQ zu schreiben. Aber dort wird in einer einzigen
Funktion erst gelesen, dann werden die Daten verändert und dann wieder zurückgeschrieben.
Das tritt ja aber in der Praxis eher selten auf.
&lt;/p&gt;
&lt;p&gt;
Also habe ich mich gefragt, was LINQ tut, wenn ich den DataContext einfach neu instanziere
und dann einfach mein Objekt per Add an die Tabelle hinzufüge. Na ja,wie zu erwarten,
hat LINQ gemeldet, dass der entsprechende Primary Key bereits existiert. Also was
tun? Den gesamten DataContext in die Session legen? Dass das keine gute Idee ist,
habe ich ziemlich schnell rausgefunden. Der DataContext skaliert sehr schlecht, da
er ein eingebautes Change-Tracking, Identity Tracking und sonst noch ein paar Nettigkeiten
hat, die sich aber in einer Web_Anwendung recht eklig verhalten können.
&lt;/p&gt;
&lt;p&gt;
Nach einigem Suchen bin ich dann drauf gekommen, dass es auch noch eine Attach-Methode
gibt. Damit konnte ich mein Problem schön lösen. Das Ergebnis für das Schreiben sieht
nun so aus:
&lt;/p&gt;
&lt;div&gt;&lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SaveProductVersion(cProductVersion
_ProductVersion) { DataContext dataContextProducts = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; DataContext(&lt;span style="color: #006080"&gt;"Data
Source=NOTEBOOK_VISTA;Initial Catalog=ValuePlanner_2008;Integrated Security=True"&lt;/span&gt;); &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (_ProductVersion.ID
== 0) { dataContextProducts.GetTable&amp;lt;cProductVersion&amp;gt;().Add(_ProductVersion);
} &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; { dataContextProducts.GetTable&amp;lt;cProductVersion&amp;gt;().Attach(_ProductVersion,
true); } dataContextProducts.SubmitChanges(); }&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Hier wird abgefragt, ob es eine neue Produktversion ist (ID == 0). Wenn ja, dann füge
ich die per Add hinzu (die ID wird von LINQ automatisch vergeben). Bei einem bestehenden
Projekt verwende ich die Attach-Methode. Ganz einfach, wenn mans weiss. Wichtig ist
noch, dass alle Properties des Objektes das Attribut UpdateCheck=none benötigen.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.artiso.com/ProBlog/aggbug.ashx?id=b0ff908d-bdf9-4937-aa10-74d266ff8709" /&gt;</description>
      <comments>http://www.artiso.com/ProBlog/CommentView,guid,b0ff908d-bdf9-4937-aa10-74d266ff8709.aspx</comments>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.artiso.com/ProBlog/Trackback.aspx?guid=033c75a2-2bac-4b67-a7c4-fb7ec1f0501b</trackback:ping>
      <pingback:server>http://www.artiso.com/ProBlog/pingback.aspx</pingback:server>
      <pingback:target>http://www.artiso.com/ProBlog/PermaLink,guid,033c75a2-2bac-4b67-a7c4-fb7ec1f0501b.aspx</pingback:target>
      <dc:creator>Thomas Schissler</dc:creator>
      <wfw:comment>http://www.artiso.com/ProBlog/CommentView,guid,033c75a2-2bac-4b67-a7c4-fb7ec1f0501b.aspx</wfw:comment>
      <wfw:commentRss>http://www.artiso.com/ProBlog/SyndicationService.asmx/GetEntryCommentsRss?guid=033c75a2-2bac-4b67-a7c4-fb7ec1f0501b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Wenn man mit LINQ to SQL arbeitet, dann steht man sehr schnell vor dem Problem,
dass man sehen möchte, wass denn LINQ mit der Datenbank so treibt. Der SQL Profiler
kann zwar die abgesetzten SQL-Statements anzeigen, die zurückgegebenen Ergebnisse
muss mann dann aber von Hand abfragen. Viel eleganter geht es mit dem <a href="http://www.scottgu.com/blogposts/linqquery/SqlServerQueryVisualizer.zip">LINQ
to SQL Debug Visualizer</a> von Scott Guthrie. Damit kann man die Abfrage im Debug-Modus
von Visual Studio 2008 einfach anzeigen lassen:
</p>
        <p>
          <img src="http://www.scottgu.com/blogposts/linqtosql3/step4.jpg" />
        </p>
        <p>
          <img src="http://www.scottgu.com/blogposts/linqtosql3/step5.jpg" />
        </p>
        <p>
Mit dem Execute-Button kann man die Abfrage einfach ausführen und das Ergebnis anzeigen
lassen.
</p>
        <p>
          <img src="http://www.scottgu.com/blogposts/linqtosql3/step6.jpg" />
        </p>
        <p>
Ein echt cooles Tool. Download und eine Installationsanleitung gibt es <a href="http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx">hier</a>.
</p>
        <p>
          <a href="http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx">LINQ
to SQL Debug Visualizer - ScottGu's Blog</a>
        </p>
        <img width="0" height="0" src="http://www.artiso.com/ProBlog/aggbug.ashx?id=033c75a2-2bac-4b67-a7c4-fb7ec1f0501b" />
      </body>
      <title>LINQ to SQL Debug Visualizer - ScottGu's Blog</title>
      <guid isPermaLink="false">http://www.artiso.com/ProBlog/PermaLink,guid,033c75a2-2bac-4b67-a7c4-fb7ec1f0501b.aspx</guid>
      <link>http://www.artiso.com/ProBlog/PermaLink,guid,033c75a2-2bac-4b67-a7c4-fb7ec1f0501b.aspx</link>
      <pubDate>Thu, 16 Aug 2007 08:53:05 GMT</pubDate>
      <description>&lt;p&gt;
Wenn man mit LINQ to SQL arbeitet, dann&amp;nbsp;steht man sehr schnell vor dem Problem,
dass&amp;nbsp;man sehen möchte, wass denn LINQ mit der Datenbank so treibt. Der SQL Profiler
kann zwar die abgesetzten SQL-Statements anzeigen, die&amp;nbsp;zurückgegebenen Ergebnisse
muss mann dann aber von Hand abfragen. Viel eleganter geht es mit dem &lt;a href="http://www.scottgu.com/blogposts/linqquery/SqlServerQueryVisualizer.zip"&gt;LINQ
to SQL Debug Visualizer&lt;/a&gt; von Scott Guthrie. Damit kann man die Abfrage im Debug-Modus
von Visual Studio 2008 einfach anzeigen lassen:
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.scottgu.com/blogposts/linqtosql3/step4.jpg"&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.scottgu.com/blogposts/linqtosql3/step5.jpg"&gt;
&lt;/p&gt;
&lt;p&gt;
Mit dem Execute-Button kann man die Abfrage einfach ausführen und das Ergebnis anzeigen
lassen.
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.scottgu.com/blogposts/linqtosql3/step6.jpg"&gt;
&lt;/p&gt;
&lt;p&gt;
Ein echt cooles Tool. Download und eine Installationsanleitung gibt es &lt;a href="http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx"&gt;hier&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx"&gt;LINQ
to SQL Debug Visualizer - ScottGu's Blog&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.artiso.com/ProBlog/aggbug.ashx?id=033c75a2-2bac-4b67-a7c4-fb7ec1f0501b" /&gt;</description>
      <comments>http://www.artiso.com/ProBlog/CommentView,guid,033c75a2-2bac-4b67-a7c4-fb7ec1f0501b.aspx</comments>
      <category>LINQ</category>
    </item>
    <item>
      <trackback:ping>http://www.artiso.com/ProBlog/Trackback.aspx?guid=da96e299-698b-4f4d-b4d2-71cba3300ee0</trackback:ping>
      <pingback:server>http://www.artiso.com/ProBlog/pingback.aspx</pingback:server>
      <pingback:target>http://www.artiso.com/ProBlog/PermaLink,guid,da96e299-698b-4f4d-b4d2-71cba3300ee0.aspx</pingback:target>
      <dc:creator>Thomas Schissler</dc:creator>
      <wfw:comment>http://www.artiso.com/ProBlog/CommentView,guid,da96e299-698b-4f4d-b4d2-71cba3300ee0.aspx</wfw:comment>
      <wfw:commentRss>http://www.artiso.com/ProBlog/SyndicationService.asmx/GetEntryCommentsRss?guid=da96e299-698b-4f4d-b4d2-71cba3300ee0</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Scott Gutherie hat in seinem Blog eine interessante Artikel-Serie zu LINQ to SQL 
</p>
        <blockquote>
          <p>
            <strong>
              <u>Data Access Improvements with LINQ to SQL</u>
            </strong>
          </p>
          <p>
LINQ to SQL is a built-in OR/M (object relational mapper) in .NET 3.5.  It enables
you to model relational databases using a .NET object model.  You can then
query the database using LINQ, as well as update/insert/delete data from it. 
LINQ to SQL fully supports transactions, views, and stored procedures.  It also
provides an easy way to integrate business logic and validation rules into your data
model.  Below are some of the articles I've written that explore how to use it:
</p>
          <ul>
            <li>
              <a href="http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx" target="_blank">
                <u>
                  <font color="#800080">Part
1: Introduction to LINQ to SQL</font>
                </u>
              </a>
            </li>
            <li>
              <a href="http://weblogs.asp.net/scottgu/archive/2007/05/29/linq-to-sql-part-2-defining-our-data-model-classes.aspx" target="_blank">
                <u>
                  <font color="#0066cc">Part
2: Defining our Data Model Classes</font>
                </u>
              </a>
            </li>
            <li>
              <a href="http://weblogs.asp.net/scottgu/archive/2007/06/29/linq-to-sql-part-3-querying-our-database.aspx" target="_blank">
                <u>
                  <font color="#0066cc">Part
3: Querying our Database</font>
                </u>
              </a>
            </li>
            <li>
              <a href="http://weblogs.asp.net/scottgu/archive/2007/07/11/linq-to-sql-part-4-updating-our-database.aspx" target="_blank">
                <u>
                  <font color="#0066cc">Part
4: Updating our Database</font>
                </u>
              </a>
            </li>
            <li>
              <a href="http://weblogs.asp.net/scottgu/archive/2007/07/16/linq-to-sql-part-5-binding-ui-using-the-asp-linqdatasource-control.aspx" target="_blank">
                <u>
                  <font color="#800080">Part
5: Binding UI using the ASP:LinqDataSource Control</font>
                </u>
              </a>
            </li>
          </ul>
          <p>
I'll be adding several more articles to my series above in the weeks ahead. 
I think you'll find that LINQ to SQL makes it dramatically easier to build much
cleaner data models, and write much cleaner data code.
</p>
        </blockquote>
        <img width="0" height="0" src="http://www.artiso.com/ProBlog/aggbug.ashx?id=da96e299-698b-4f4d-b4d2-71cba3300ee0" />
      </body>
      <title>LINQ to SQL</title>
      <guid isPermaLink="false">http://www.artiso.com/ProBlog/PermaLink,guid,da96e299-698b-4f4d-b4d2-71cba3300ee0.aspx</guid>
      <link>http://www.artiso.com/ProBlog/PermaLink,guid,da96e299-698b-4f4d-b4d2-71cba3300ee0.aspx</link>
      <pubDate>Sat, 28 Jul 2007 02:39:55 GMT</pubDate>
      <description>&lt;p&gt;
Scott Gutherie hat in seinem Blog eine interessante Artikel-Serie zu LINQ to SQL &lt;blockquote&gt; 
&lt;p&gt;
&lt;strong&gt;&lt;u&gt;Data Access Improvements with LINQ to SQL&lt;/u&gt;&lt;/strong&gt; 
&lt;p&gt;
LINQ to SQL is a built-in OR/M (object relational mapper) in .NET 3.5.&amp;nbsp; It enables
you to model relational databases using a&amp;nbsp;.NET object model.&amp;nbsp; You can then
query the database using LINQ, as well as update/insert/delete data from it.&amp;nbsp;
LINQ to SQL fully supports transactions, views, and stored procedures.&amp;nbsp; It also
provides an easy way to integrate business logic and validation rules into your data
model.&amp;nbsp; Below are some of the articles I've written that explore how to use it:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx" target="_blank"&gt;&lt;u&gt;&lt;font color="#800080"&gt;Part
1: Introduction to LINQ to SQL&lt;/font&gt;&lt;/u&gt;&lt;/a&gt; 
&lt;li&gt;
&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/05/29/linq-to-sql-part-2-defining-our-data-model-classes.aspx" target="_blank"&gt;&lt;u&gt;&lt;font color="#0066cc"&gt;Part
2: Defining our Data Model Classes&lt;/font&gt;&lt;/u&gt;&lt;/a&gt; 
&lt;li&gt;
&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/06/29/linq-to-sql-part-3-querying-our-database.aspx" target="_blank"&gt;&lt;u&gt;&lt;font color="#0066cc"&gt;Part
3: Querying our Database&lt;/font&gt;&lt;/u&gt;&lt;/a&gt; 
&lt;li&gt;
&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/07/11/linq-to-sql-part-4-updating-our-database.aspx" target="_blank"&gt;&lt;u&gt;&lt;font color="#0066cc"&gt;Part
4: Updating our Database&lt;/font&gt;&lt;/u&gt;&lt;/a&gt; 
&lt;li&gt;
&lt;a href="http://weblogs.asp.net/scottgu/archive/2007/07/16/linq-to-sql-part-5-binding-ui-using-the-asp-linqdatasource-control.aspx" target="_blank"&gt;&lt;u&gt;&lt;font color="#800080"&gt;Part
5: Binding UI using the ASP:LinqDataSource Control&lt;/font&gt;&lt;/u&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
I'll be adding several more articles to my series above in the weeks ahead.&amp;nbsp;
I think you'll find that LINQ to SQL makes it dramatically easier to&amp;nbsp;build much
cleaner data models, and write much cleaner data code.
&lt;/p&gt;
&lt;/blockquote&gt;&lt;img width="0" height="0" src="http://www.artiso.com/ProBlog/aggbug.ashx?id=da96e299-698b-4f4d-b4d2-71cba3300ee0" /&gt;</description>
      <comments>http://www.artiso.com/ProBlog/CommentView,guid,da96e299-698b-4f4d-b4d2-71cba3300ee0.aspx</comments>
      <category>.Net 3.5;LINQ;SQL</category>
    </item>
  </channel>
</rss>