LINQ to SQL ForumQuestions and discussion about LINQ to SQL. For LINQ to Entities see the “ADO.NET Entity Framework and LINQ to Entities" forum.© 2009 Microsoft Corporation. All rights reserved.Wed, 25 Nov 2009 21:47:29 Z91085c4d-89fc-483f-8274-171226580741http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/7c0b408a-d007-4606-8b7c-469749e42935http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/7c0b408a-d007-4606-8b7c-469749e42935Khaliquehttp://social.msdn.microsoft.com/Profile/en-US/?user=KhaliqueError SUMming values that include null values as wellI am having problem with following query:<br/><span style="font-size:x-small"><span style="font-size:x-small"> <p> </p> </span></span> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small"></span><span style="color:#0000ff;font-size:x-small"> <p> </p> </span></span> <p> </p> <p><span style="font-size:x-small">Here object P contains Q. However, Q may be missing for some P. Q has an Amount attribute. I am trying to sum that amount in Q belonging at the level of P.<br/>Since Q.amount is numeric, PTotal is also of numeric type and it does not accept null values and I get an error. I tried to use the above expression but it does not work either and I get the same error. Can someone help me fix this?<br/>Thanks<br/></span></p> </p> <pre>var aList = from P in DataContext.P where P.Id == SelectedId orderby P.Name ascending select new { PId = P.Id, Name = P.Name, PAmount = P.Amount, PTotal = P.Q.Sum(o =&gt; (o.Amount == null ? 0 : o.Amount)) };</pre> <span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small"> <p> </p> </span></span>Wed, 25 Nov 2009 21:47:29 Z2009-11-25T21:47:29Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/18fc67c9-f1d6-43e3-90ca-62f945984f0dhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/18fc67c9-f1d6-43e3-90ca-62f945984f0dhaggis999http://social.msdn.microsoft.com/Profile/en-US/?user=haggis999Dynamic LINQ query error: Overload resolution failed ....<p>I have some limited experience in the creation of normal LINQ to SQL queries but I now want to find a method of generating dynamic queries that will respond to user selections in various DropDownLists on my ASP.NET 3.5 web page. The following link to Scott Guthrie's blog article on dynamic LINQ queries looked like it would provide a potential solution:</p> <p><a href="http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx">http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx</a></p> <p>Unfortunately, I can't get dynamic LINQ queries to work. I have downloaded the VB Dynamic Query Library, copied Dynamic.vb into my ASP.NET site and referenced System.Linq.Dynamic in my VB.NET code behind page. However, my page fails with the compilation error message &quot;Overload resolution failed because no accessible 'Where' can be called with these arguments&quot; on the following line of code: </p> <div style="background-color:white;color:black"> <pre>Recipients = myDBC.Entrants.<span style="color:blue">Where</span>(<span style="color:#a31515">&quot;FirstName = 'David'&quot;</span>) </pre> </div> <br/>I am probably making a very basic error somewhere. Any help would be much appreciated. <p>David </p>Mon, 23 Nov 2009 11:19:18 Z2009-11-25T21:28:10Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/188d5c73-50f5-48a4-8cae-6b4129811d7ahttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/188d5c73-50f5-48a4-8cae-6b4129811d7asroughleyhttp://social.msdn.microsoft.com/Profile/en-US/?user=sroughleyCommit single, specific entities or prevent specific entities from being committedHi all,<br/><br/>We regularly come across situations where we need to insert/update only a specific, single object or objects regardless what else has changed and we cannot seem to do this in LINQ to SQL. Sounds simple enough but I'm completely stuck. Any ideas?<br/><br/>Regards,<br/><br/>StephenWed, 25 Nov 2009 18:16:33 Z2009-11-25T18:16:34Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/4dfd3f91-f757-430b-98a3-75f582502dd6http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/4dfd3f91-f757-430b-98a3-75f582502dd6chuck02323http://social.msdn.microsoft.com/Profile/en-US/?user=chuck02323Linq To Sql XML fields don't update.Is their a work around for getting XML fields to Update when using a Linq datasource?<br/> For reference see https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=360433&amp;wa=wsignin1.0#tabs<br/> which is a similar problem.<br/> <br/> If I use a LinqDatasource and attach to the Updating event.  The XML field does not get updated.  The ProgramCode field does get updated.<br/> <br/>   protected void LinqDataSource1_Updating(object sender, LinqDataSourceUpdateEventArgs e)<br/>         {<br/>             Registration reg = (Registration)e.NewObject;<br/>             reg.XMLData = new XElement(&quot;ContextData&quot;, Util.AuditHelper.GetContextData());<br/>             reg.ProgramCode = &quot;A&quot;;<br/>Wed, 25 Nov 2009 16:58:42 Z2009-11-25T17:09:16Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/5d0c40b5-9408-48c1-ad3c-949bdc2fbe47http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/5d0c40b5-9408-48c1-ad3c-949bdc2fbe47Thomas Koellehttp://social.msdn.microsoft.com/Profile/en-US/?user=Thomas%20KoelleLinqDataSource Select should give strong typeI have a LinqDataSource, and in the select, I would Like to have something else than an anonymous type. I assume I would like to type something like this:<br/> <div style="color:black;background-color:white"><br/><br/><span style="font-size:x-small;color:#0000ff"><span style="font-size:x-small;color:#0000ff"><font size=2 color="#0000ff"><font size=2 color="#0000ff"> <p><span style="color:#000000">&lt;asp:LinqDataSource TableName=&quot;Foo&quot; Select=&quot;new KeyValuePair&lt;int, string&gt;(Id, Title)&quot; ContextTypeName...</span></p> </font></font></span><font size=2 color="#0000ff"> <p> </p> </font></span> <p> </p> <br/><br/></div> <p>But it doesn't work. Ofcouse I could get an anoynous type with a Key and a Value, but it is just not the same.</p> <p> </p> <p>Any good Ideas?</p>Wed, 25 Nov 2009 15:43:47 Z2009-11-25T15:43:47Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/0e315d36-59ef-41a9-9e22-2b94087775d8http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/0e315d36-59ef-41a9-9e22-2b94087775d8martynhhttp://social.msdn.microsoft.com/Profile/en-US/?user=martynhLINQ to SQL - 3 Tier Design<span style="font-family:verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;font-size:13px;white-space:pre-wrap">Hi,  </span> <div><span style="font-family:verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;font-size:small"><span style="font-size:13px;white-space:pre-wrap"><br/></span></span></div> <div><span style="font-family:verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;font-size:13px;white-space:pre-wrap">I've just started looking at LINQ to SQL and am very impressed with it, but I have a query about how it should fit into the data access layer of a 3 tier design.  </span></div> <div><span style="font-family:verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;font-size:small"><span style="font-size:13px;white-space:pre-wrap"><br/></span></span></div> <div><span style="font-family:verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;font-size:13px;white-space:pre-wrap">It seems that LINQ to SQL is such a clean and concise technology that it has the potential to completely replace the DAL in an application as it does exactly the same job.   Even if the DAL was to remain with LINQ to SQL as its internal workings, the DAL would be such a thin wrapper that it almost seems pointless.  </span></div> <div><span style="font-family:verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;font-size:small"><span style="font-size:13px;white-space:pre-wrap"><br/></span></span></div> <div><span style="font-family:verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;font-size:13px;white-space:pre-wrap">Also, as the generated entity object have the ability to update the database simply by changing their properties, surely this renders the DAL useless.. Or at least provides a path for poorly written code to bypass the DAL?  </span></div> <div><span style="font-family:verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;font-size:small"><span style="font-size:13px;white-space:pre-wrap"><br/></span></span></div> <div><span style="font-family:verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;font-size:13px;white-space:pre-wrap">It seems to me that the best way to use Linq to Sql is to scrap the DAL and allow the business logic layer to interact directly with the DataContext object, but this goes against every software design principle I can think of.</span> <div><span style="font-family:verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;font-size:small"><span style="font-size:13px;white-space:pre-wrap"><br/></span></span></div> <div><span style="font-family:verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;font-size:13px;white-space:pre-wrap">I guess im just a bit confused and looking for some best practice pointers.</span></div> <div><span style="font-family:verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;font-size:13px;white-space:pre-wrap">Any help would be much appreciated.</span></div> <div><span style="font-family:verdana, geneva, lucida, 'lucida grande', arial, helvetica, sans-serif;font-size:13px;white-space:pre-wrap"> Martyn.</span></div> </div>Tue, 24 Nov 2009 21:06:27 Z2009-11-25T14:07:48Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/bbc6465a-5905-47a7-9a22-f65a880e81f7http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/bbc6465a-5905-47a7-9a22-f65a880e81f7Aleksander Ohttp://social.msdn.microsoft.com/Profile/en-US/?user=Aleksander%20OGetting count of results without an additional queryHello! I'm trying to get number of results in collection that I've got with L2SQL but it causes a second database query.  <div><br/></div> <div>In other words this code generates two separate SQL queries:</div> <div> <pre lang="x-c#">Model.Nodes = Nodes .Take&lt;SideBarModel.NodeModel&gt;(NodesPerPage) .ToList&lt;SideBarModel.NodeModel&gt;(); NodesNum = Nodes.Count&lt;SideBarModel.NodeModel&gt;();</pre> How can I avoid this?</div>Tue, 24 Nov 2009 15:38:22 Z2009-11-25T13:28:56Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/46f6b750-c5f6-43ad-bc30-52d17b3ced32http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/46f6b750-c5f6-43ad-bc30-52d17b3ced32ti123http://social.msdn.microsoft.com/Profile/en-US/?user=ti123Complex QueryHi,<br/>I'm quite new to Linq2SQL, and I need to write a query which I'm not sure how to do.<br/>I have 2 tables: Persons and Emails. Naturally, there is more than one Email for every Person. However, every person has one (or zero) default email, designated by a &quot;is_default&quot; column in the Emails table.<br/>What I want to do is this: Retrieve all the persons, with their default email address (single record per person). If the person has no default email, the query will return only his name, and leave the email empty.<br/>How can that be done using Linq2SQL? Can I do that in a single query?<br/><br/>Thanks!Tue, 24 Nov 2009 13:35:18 Z2009-11-25T09:30:51Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/dadb743e-1326-4188-8205-9394b1f238d7http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/dadb743e-1326-4188-8205-9394b1f238d7d_dhttp://social.msdn.microsoft.com/Profile/en-US/?user=d_ddatagrivew small problemhi <br/>i m new in vb<br/>i have small problem with datagridview <br/>i dont know whats parts im missing<br/>lets say i have tow tables<br/>1-items info <br/>2-sales  invoice <br/>what i need when i type the items number in datagridview cell 0 (datagridview  that belong to invoice tables)<br/>its bring the data for the item like item price,name...etc<br/> i tried in cellendedit <br/>but i dont know the right way to do it<br/>i dont want to use textbox  ,and if there is anything better to use it than datagridview please let me know<br/>any help ?<br/>thanks for every oneWed, 25 Nov 2009 08:22:12 Z2009-11-25T08:22:12Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/3f412ed4-c52b-4622-8b4e-e0207581ca63http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/3f412ed4-c52b-4622-8b4e-e0207581ca63Miguel T.http://social.msdn.microsoft.com/Profile/en-US/?user=Miguel%20T.Why am I getting an error on DeleteAllOnSubmit while trying to delete a record from a database?<p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US>Hi,</span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US> </span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US>I have two tables with the following fields:</span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US> </span></p> <table class=MsoNormalTable style="margin:auto auto auto 3.25pt;width:132pt;border-collapse:collapse" border=0 cellspacing=0 cellpadding=0 width=176> <tbody> <tr style="height:12.75pt"> <td style="padding-bottom:0cm;background-color:transparent;padding-left:3.5pt;width:68pt;padding-right:3.5pt;height:12.75pt;padding-top:0cm;border:windowtext 1pt solid" width=91 valign=bottom> <p class=MsoNormal style="margin:0cm 0cm 0pt"><strong><span style="font-family:'Arial Narrow';font-size:10pt" lang=EN-GB>Assets</span></strong></p> </td> <td style="border-bottom:windowtext 1pt solid;border-left:#ece9d8;padding-bottom:0cm;background-color:transparent;padding-left:3.5pt;width:64pt;padding-right:3.5pt;height:12.75pt;border-top:windowtext 1pt solid;border-right:windowtext 1pt solid;padding-top:0cm" width=85 valign=bottom> <p class=MsoNormal style="margin:0cm 0cm 0pt"><strong><span style="font-family:'Arial Narrow';font-size:10pt">HistoricalPrices</span></strong></p> </td> </tr> <tr style="height:12.75pt"> <td style="border-bottom:windowtext 1pt solid;border-left:windowtext 1pt solid;padding-bottom:0cm;background-color:transparent;padding-left:3.5pt;width:68pt;padding-right:3.5pt;height:12.75pt;border-top:#ece9d8;border-right:windowtext 1pt solid;padding-top:0cm" width=91 valign=bottom> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:'Arial Narrow';font-size:10pt">AssetID</span></p> </td> <td style="border-bottom:windowtext 1pt solid;border-left:#ece9d8;padding-bottom:0cm;background-color:transparent;padding-left:3.5pt;width:64pt;padding-right:3.5pt;height:12.75pt;border-top:#ece9d8;border-right:windowtext 1pt solid;padding-top:0cm" width=85 valign=bottom> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:'Arial Narrow';font-size:10pt">Date</span></p> </td> </tr> <tr style="height:12.75pt"> <td style="border-bottom:windowtext 1pt solid;border-left:windowtext 1pt solid;padding-bottom:0cm;background-color:transparent;padding-left:3.5pt;width:68pt;padding-right:3.5pt;height:12.75pt;border-top:#ece9d8;border-right:windowtext 1pt solid;padding-top:0cm" width=91 valign=bottom> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:'Arial Narrow';font-size:10pt">Ticker</span></p> </td> <td style="border-bottom:windowtext 1pt solid;border-left:#ece9d8;padding-bottom:0cm;background-color:transparent;padding-left:3.5pt;width:64pt;padding-right:3.5pt;height:12.75pt;border-top:#ece9d8;border-right:windowtext 1pt solid;padding-top:0cm" width=85 valign=bottom> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:'Arial Narrow';font-size:10pt">AssetID</span></p> </td> </tr> <tr style="height:12.75pt"> <td style="border-bottom:windowtext 1pt solid;border-left:windowtext 1pt solid;padding-bottom:0cm;background-color:transparent;padding-left:3.5pt;width:68pt;padding-right:3.5pt;height:12.75pt;border-top:#ece9d8;border-right:windowtext 1pt solid;padding-top:0cm" width=91 valign=bottom> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:'Arial Narrow';font-size:10pt">Name</span></p> </td> <td style="border-bottom:windowtext 1pt solid;border-left:#ece9d8;padding-bottom:0cm;background-color:transparent;padding-left:3.5pt;width:64pt;padding-right:3.5pt;height:12.75pt;border-top:#ece9d8;border-right:windowtext 1pt solid;padding-top:0cm" width=85 valign=bottom> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:'Arial Narrow';font-size:10pt">OpenPrice</span></p> </td> </tr> <tr style="height:12.75pt"> <td style="border-bottom:windowtext 1pt solid;border-left:windowtext 1pt solid;padding-bottom:0cm;background-color:transparent;padding-left:3.5pt;width:68pt;padding-right:3.5pt;height:12.75pt;border-top:#ece9d8;border-right:windowtext 1pt solid;padding-top:0cm" width=91 valign=bottom> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:'Arial Narrow';font-size:10pt">…</span></p> </td> <td style="border-bottom:windowtext 1pt solid;border-left:#ece9d8;padding-bottom:0cm;background-color:transparent;padding-left:3.5pt;width:64pt;padding-right:3.5pt;height:12.75pt;border-top:#ece9d8;border-right:windowtext 1pt solid;padding-top:0cm" width=85 valign=bottom> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:'Arial Narrow';font-size:10pt">…</span></p> </td> </tr> </tbody> </table> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US> </span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US>I have a 1-to-many relationship between the table Assets and the table HistoricalPrices. Because of this, in order to delete an asset I first need to delete all the historical prices of that asset.</span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US> </span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US>I get the following InvalidOperationException error <em style="">“Cannot remove an entity that has not been attached.”</em> <span style=""> </span>on the <em style="">DeleteAllOnSubmit</em> line of code. This is my code:</span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US> </span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:'Courier New';color:#2b91af;font-size:9pt" lang=EN-GB>TTSDatabaseDataContext</span><span style="font-family:'Courier New';font-size:9pt" lang=EN-GB> db = <span style="color:blue">new</span> <span style="color:#2b91af">TTSDatabaseDataContext</span>();</span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:'Courier New';color:#2b91af;font-size:9pt" lang=EN-GB>Asset</span><span style="font-family:'Courier New';font-size:9pt" lang=EN-GB> asset = <span style="color:blue">new</span> <span style="color:#2b91af">Asset</span>();</span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:'Courier New';color:green;font-size:9pt" lang=EN-GB>// Get asset information from the ComboBox which contains asset items</span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:'Courier New';font-size:9pt" lang=EN-GB>asset = (<span style="color:#2b91af">Asset</span>)ticker.SelectedItem;<span style="">      </span></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:'Courier New';color:green;font-size:9pt" lang=EN-GB>// Delete the historical prices of the asset to delete</span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:'Courier New';font-size:9pt" lang=EN-GB>db.HistoricalPrices.DeleteAllOnSubmit(asset.HistoricalPrices);</span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:'Courier New';color:green;font-size:9pt" lang=EN-GB>// Delete the asset</span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:'Courier New';font-size:9pt" lang=EN-GB>db.Assets.DeleteOnSubmit(asset);</span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:'Courier New';font-size:9pt" lang=EN-GB>db.SubmitChanges();</span><span style="font-family:Arial;font-size:9pt" lang=EN-US></span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US> </span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US>What is incorrect in my code? I’m using an example very similar to one that I found on the book “Pro LINQ Language Integrated Query in C# 2008”.</span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US> </span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US>I’m developing an application using Visual C# 2008 Express Edition and SQL Server Express Edition.</span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US> </span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US>Thanks.</span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US> </span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US>Best regards,</span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US>Miguel.</span></p> <p class=MsoNormal style="margin:0cm 0cm 0pt"><span style="font-family:Arial;font-size:10pt" lang=EN-US> </span></p>Thu, 19 Nov 2009 20:11:11 Z2009-11-25T04:48:52Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/04280c06-ce23-4664-9992-5ef3fb516503http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/04280c06-ce23-4664-9992-5ef3fb516503ViewStatehttp://social.msdn.microsoft.com/Profile/en-US/?user=ViewStateIts complicated even for a titleHi all,<br/><br/>Here is the scene.....<br/>I 2 separate contexts in LINQ, the actual database is one, and the contexts basicaly break concerns, and in this case, I using 3 tables.<br/><br/>Table 1 (AccountId) (Context 1)<br/><br/>Table 2 (PersonId) (Context 2)<br/><br/>Table 3 (AccountId, PersonId) (Context 2)<br/><br/>So what happens here is that (Context 2) can only create a record on Table 3 after a record has been created in Table 1.<br/><br/>With that in mind, I created a ActionScheduler, that takes all 3 Linq to SQL objects, and creates watchers on the properties that matter (AccountId, PersonId), and when both of them are not the default values ( 0 ), meanind that they have being inserted, the 3rd one (Table 3) object is then assined the AccountId, and added to Table 2s list of Table 3 objects.<br/><br/>So what I tecnically would have to do is basically call SubmitChanges 2 times and things would be good.<br/><br/>Well thats exactly when things fall apart. I make the first call, Table 1, gets inserted triggering the event on the ActionScheduler, that then updates Table 3 object, then Table 2 get inserted triggering Table 3 object, which now meet the requirement (Both PersonId, AccountId are valid), Table 3 object is added to Table 2 object.<br/>The second save is called, and there is no changes here , so nothing gets added at all, now if while having the same contexts open I add another set of objects, and save all over again, the new Table 3 object does not get added (same behavior) but the other one does with perfect values, so it seem like this guys is always one step behind.<br/><br/>Any sugestions? Is there a better way of doing this, how exaclty is the SubmitChanges lifecycle?<br/><br/>Sorry for all the questions, but this is really bugging me. And an obvious thanks.<hr class="sig">Binding you through life - Se serve, marque!!!Wed, 25 Nov 2009 01:05:54 Z2009-11-25T01:05:56Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/c3149c06-4bc1-4a01-af6f-fea9041e68dehttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/c3149c06-4bc1-4a01-af6f-fea9041e68deMDMourahttp://social.msdn.microsoft.com/Profile/en-US/?user=MDMouraCannot add an entity with a key that is already in use.Hello,<br/> <br/> I am creating two Assets using LinqToSQL as follows:<br/> <br/>       ISession session = new Context();<br/>       AssetRepository assetRepository = new AssetRepository(session);<br/>       assetRepository.Create(new Asset { Id = 1, Mime = new Mime { Id = 9 }});<br/>       assetRepository.Create(new Asset { Id = 2, Mime = new Mime { Id = 9 }});<br/>       session.Commit();<br/> <br/> Session implements Unit of Work pattern:<br/> <br/>   public interface ISession {    <br/>     void Commit();<br/>     void Rollback();<br/>   } // ISession<br/> <br/>   public partial class Context : DataContext, ISession {<br/>     public void Commit() {<br/>       SubmitChanges();<br/>     } // Commit<br/>     public void Rollback() {<br/>       Dispose();<br/>     } // Rollback<br/>   } // Context<br/> <br/> What ever I do I always get the following error:<br/> &quot;Cannot add an entity with a key that is already in use.&quot;<br/> <br/> On code line:<br/> _context.Mimes.Attach(mime);<br/> <br/> On my repository create asset code:<br/>     public void Create(AssetModel asset) {<br/>       <br/>       // Define entity<br/>       Asset _asset = new Asset { Id = asset.Id};<br/>       _context.Assets.InsertOnSubmit(_asset);<br/> <br/>       if (asset.Mime != null) {<br/>         Mime mime = new Mime { Id = asset.Mime.Id };<br/>         _context.Mimes.Attach(mime);<br/>         _asset.Mime = mime;<br/>       }<br/> <br/>     } // Create<br/> <br/> Basically, in each Asset there is a MimeId.<br/> <br/> Anyway, is there a way to overcome this?<br/> I am really not sure what am I doing wrong.<br/> <br/> Here is the SQL code for Assets and Mimes:<br/> <br/> create table dbo.Assets<br/> (<br/>   Id int not null,    <br/>   MimeId int not null,<br/>     constraint PK_Assets primary key clustered(Id)<br/> ) -- Assets<br/> <br/> create table dbo.Mimes<br/> (<br/>   Id int not null,<br/>   Type nvarchar(80) not null,<br/>     constraint PK_Mimes primary key clustered(Id)        <br/> ) -- Mimes<br/> <br/> alter table dbo.Assets<br/> add constraint FK_Assets_Mimes foreign key(MimeId) references dbo.Mimes(Id) on delete no action on update cascade;<br/> <br/> Note: Assets table has more columns, like Content, etc ...<br/>            But for sake of simplicity I am not including this on my code as I am just testing the relations.<br/> <br/> Could someone tell me how should I solve this?<br/> <br/> Thanks,<br/> MiguelFri, 20 Nov 2009 15:32:46 Z2009-11-24T20:32:58Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/402d6202-6eda-442c-8109-d9ada4416513http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/402d6202-6eda-442c-8109-d9ada4416513Randy Minderhttp://social.msdn.microsoft.com/Profile/en-US/?user=Randy%20MinderHow Do I Avoid This Behavior?<p>Say I have an entity that looks as follows</p> <p>public Order OrderEntity {<br/>EntityRef CustomerEntity;<br/>EntitySet OrderDetailEntity;<br/>...<br/>... <br/>}</p> <p>When I save a OrderEntity, L2S, will want to also save the entity in CustomerEntity and all the entities in OrderDetailEntity. Sometimes we want this behavior and sometimes we do not. For those times we do not, how to tell L2S not to do this?</p> <p>Thanks - Randy</p>Fri, 20 Nov 2009 19:24:56 Z2009-11-24T20:23:15Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/bf1fb5ae-3ffa-44a9-8218-5a39eec01936http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/bf1fb5ae-3ffa-44a9-8218-5a39eec01936Darko Romanovhttp://social.msdn.microsoft.com/Profile/en-US/?user=Darko%20RomanovRepeated assignments overwrite a field in queryHi all,<br/> <br/> I'm having this weird issue, look at my code:<br/> <br/> <pre lang="x-c#">var query = from rud in db.DBRud select rud; foreach(myObject p in objects) { switch(p.type) { case &quot;rudobject&quot;: //p.code now is &quot;linea_di_prodotti&quot; query = from r in query join s in db.ValueRudobject on r.id equals s.rud_id where s.field_code == p.code &amp;&amp; values.Contains(s.value) select r; break; case &quot;checkbox&quot;: //p.code now is &quot;us&quot; query = from r in query join c in db.ValueCheckbox on r.id equals c.rud_id where c.field_code == p.code &amp;&amp; values.Contains(c.value) select r; break; } }</pre> <br/> <br/> <br/> <br/> so, the query is built dynamically. But if you look at the sql produced, you'll notice that the second assignment overwrites the variable p.code! Look:<br/> <pre lang=x-sql>SELECT [t0].[id], [t0].[user] AS [user], [t0].[name], [t0].[status], [t0].[notes], [t0].[rudobject], [t0].[internal_name], [t0].[visible], [t0].[created], [t0].[modified], [t0].[locale], [t0].[metadescription], [t0].[keywords], [t0].[referer], [t0].[folder], [t0].[position] FROM [dbo].[ruds] AS [t0] INNER JOIN [dbo].[ruds_values_checkbox] AS [t1] ON [t0].[id] = [t1].[rud_id] INNER JOIN [dbo].[ruds_values_rudobject] AS [t2] ON [t0].[id] = [t2].[rud_id] WHERE ([t2].[field_code] = @p0) AND ([t2].[value] IN (@p1, @p2)) AND ([t1].[field_code] = @p3) AND ([t1].[value] IN (@p4)) AND ([t0].[locale] = @p5) AND ([t0].[rudobject] = @p6) -- @p0: Input VarChar (Size = 17; Prec = 0; Scale = 0) [linea_di_prodotto] -- @p1: Input Int (Size = 0; Prec = 0; Scale = 0) [42] -- @p2: Input Int (Size = 0; Prec = 0; Scale = 0) [43] -- @p3: Input NVarChar (Size = 17; Prec = 0; Scale = 0) [linea_di_prodotto] ERROR !!! should be &quot;us&quot; !!!!!!!!!! -- @p4: Input NVarChar (Size = 13; Prec = 0; Scale = 0) [International] -- @p5: Input VarChar (Size = 5; Prec = 0; Scale = 0) [it_IT] -- @p6: Input VarChar (Size = 8; Prec = 0; Scale = 0) [prodotto] -- Context: SqlProvider(Sql2008) Model: AttributedMetaModel Build: 3.5.30729.1 </pre> <br/> <br/> <br/> <br/> It's for sure a question of variables overwriting, because if I change the order of the items inside the variable objects (the one into the foreach) I got &quot;<em>us</em> &quot; duplicated, instead of &quot;<em>linea_di_prodotto</em> &quot;. So, the last value in p.code overwrites the value of all the other previous p.code.<br/> <br/> What do you think about? Do you have any suggestion for a workaround?<br/> <br/> thanks<br/> darko<br/> <br/>Tue, 24 Nov 2009 15:45:19 Z2009-11-24T16:37:48Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/35fb1991-afc7-4fa0-973e-bdecbf38bfcbhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/35fb1991-afc7-4fa0-973e-bdecbf38bfcbMrRichDeanhttp://social.msdn.microsoft.com/Profile/en-US/?user=MrRichDeanTake value based upon textbox valueHello all, I am creating a gridview that will be populated based upon a linq statement, the sql is as follows:<br/><br/> <pre lang=x-sql>SELECT TOP 10 IDDesc, UnitUserfield1, UnitUserfield2, ProductPercentage FROM tblOnlineReportingCOMPLETEWeights WHERE (MaterialLevel = 'Primary') AND (MaterialText = 'Paper') ORDER BY ProductPercentage DESC</pre> Now, what I would like to do is let the user specify the Top 10, so essentially it is a &quot;Top x&quot; this being defined in a textbox i.e. they type in 50 into the textbox, the linq query is executed and the gridview displays the top 50.<br/><br/>I understand that using Take is the area I want to look at, is this correct? Is this even possible?!<br/><br/>Any thoughts, muchly appreciated.<br/><br/>PS: apologies for asking thick questions, I am very new to all of this!Tue, 24 Nov 2009 10:35:47 Z2009-11-24T15:29:59Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/92b9c033-efc3-4fc2-84c1-4523e650187ahttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/92b9c033-efc3-4fc2-84c1-4523e650187aGopala Krishnahttp://social.msdn.microsoft.com/Profile/en-US/?user=Gopala%20Krishnawriting a linq query to extract data from two data sourcesCan we write a single line of linq query for extracting data from two differnet data sources <br/>i.e data source 1: a list <br/>    data source 2 : an XML fileTue, 24 Nov 2009 11:34:44 Z2009-11-24T11:47:06Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/0ab01438-2e37-4b92-a0f9-b21518b29757http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/0ab01438-2e37-4b92-a0f9-b21518b29757MrRichDeanhttp://social.msdn.microsoft.com/Profile/en-US/?user=MrRichDeanDistinct Query<div class=body>Hello all.<br/><br/>I have the following LINQ statement that appears to be working fine and dandy. Hwoever, someone has pointed out that my distinct may not be doing exactly what I want it to do (i.e. essentially group the UnitUserfield1). <br/><br/>Can someone explain the logic behind this and point me in the right direction as to how to amend this? The code is as follows:<br/><br/> <pre> var query = (from r in db.tblOnlineReportingFINALPRODUCTs where r.MemberId.Equals(&quot;FM00012&quot;) select new { unitUserfield1 = r.UnitUserfield1 }).Distinct().OrderBy(r =&gt; r.unitUserfield1);</pre> </div>Tue, 24 Nov 2009 10:29:59 Z2009-11-24T11:43:21Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/50d367a5-e5d6-4841-856c-0484c653cfa4http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/50d367a5-e5d6-4841-856c-0484c653cfa4alexandru pascanuhttp://social.msdn.microsoft.com/Profile/en-US/?user=alexandru%20pascanulinq2 sql executeQuery and database load options issue.Hello,<br/>I'm facing with the next situation:<br/>former- i've to send a direct query to database engine because of sql server in clause parameter limitation.The code is :<br/><span style="font-size:x-small"><span style="font-size:x-small"> <p> </p> </span></span> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">string</span></span><span style="font-size:x-small"> tmp = </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">string</span></span><span style="font-size:x-small">.Join(</span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">&quot;,&quot;</span></span><span style="font-size:x-small">, (</span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">from</span></span><span style="font-size:x-small"> x </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">in</span></span><span style="font-size:x-small"> ids </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">select</span></span><span style="font-size:x-small"> x.ToString()).ToArray());<span style="font-size:x-small"> </span></span></p> <p> </p> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">var</span></span><span style="font-size:x-small"> xx = bl.DataContext.ExecuteQuery&lt;</span><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">Element</span></span><span style="font-size:x-small">&gt;(</span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">&quot; select * from Elements as a where a.ElementID in (&quot;</span></span><span style="font-size:x-small"> + tmp + </span><span style="color:#a31515;font-size:x-small"><span style="color:#a31515;font-size:x-small">&quot;)&quot;</span></span><span style="font-size:x-small">).Where(x =&gt; x.Questions.Count &gt; 0);<br/><br/>latter- even though i've  database load option setted in my datacontext :<span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small"> </span></span></span><span style="color:#0000ff;font-size:x-small"></span></span>mdatacontext.LoadOptions = shape;<br/><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small"><font size=2 color="#0000ff"><font size=2 color="#0000ff"> <p>var</p> </font></font></span><font size=2 color="#0000ff"> <p> </p> </font></span></span></p> <p> </p> <p><span style="font-size:x-small"> shape = </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">new</span></span><span style="font-size:x-small"> </span><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">DataLoadOptions</span></span><span style="font-size:x-small">();<font size=2> <p>shape.LoadWith&lt;</p> </font></span></p> <p><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">Element</span></span><span style="font-size:x-small">&gt;(x =&gt; x.Questions);<font size=2> <p>shape.LoadWith&lt;</p> </font></span></p> <p><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">Section</span></span><span style="font-size:x-small">&gt;(x =&gt; x.Questions); <p>mdatacontext.LoadOptions = shape;</p> <font size=2> <p> </p> </font></span></p> <p><br/>The linq2sql engine seems to igonore them and when i'm executing this query a query is generated for every parent item -i mean element object.<br/>Can you help me to sort this out please?<br/><br/>Thank you!</p> <p> </p> <p> </p> <p> </p>Thu, 19 Nov 2009 13:02:43 Z2009-11-24T06:55:41Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/b3c13f39-6173-4348-9036-76e8a57a6f4ahttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/b3c13f39-6173-4348-9036-76e8a57a6f4aMarcelGosselinhttp://social.msdn.microsoft.com/Profile/en-US/?user=MarcelGosselinWhy is ToLookup() dependent on load options in Linq2Sql?<div class=post-text> <p>I recently stumbled upon a problem in Linq2SQL that I explain below.</p> <p>Lets say I have 3 tables Posts, PostTags and Tags defining a many-to-many relationship. I want to get a lookup table that will give me all the Posts related to a given tag so I use the following code:</p> <p> </p> <div style="color:Black;background-color:White"> <pre><span style="color:Blue">return</span> dataContext.PostTags.ToLookup(pt =&gt; pt.Tag, pt =&gt; pt.Post); </pre> </div> <br/> In unit test all went fine but in the real application, it didn't work. I found out that I had different load options between my unit test and my application. <p>When <code>dataContext.DeferredLoadingEnabled = true;</code> , everything is fine and works as expected but when <code>dataContext.DeferredLoadingEnabled = false;</code> and you don't have the load options from <code>PostTags</code> to <code>Post</code> and <code>Tag</code> , the lookup returned contains a single key (null) with an empty array for value. The generated SQL is</p> <p> </p> <div style="color:Black;background-color:White"> <pre><span style="color:Blue">SELECT</span> [t0].[PostID], [t0].[TagID]<br/> <span style="color:Blue">FROM</span> [dbo].[PostTags] <span style="color:Blue">AS</span> [t0] </pre> </div> <br/> So when it generates the lookup, <code>pt =&gt; pt.Post</code> returns <code>null</code> and the same goes for Tags. <div class=post-text> <p>I found a way to make it work no matter what the DeferredLoadingEnabled property value is and whatever the loadoptions are:</p> <p> </p> <div style="color:Black;background-color:White"> <pre><span style="color:Blue">var</span> lookup = (<span style="color:Blue">from</span> pt <span style="color:Blue">in</span> dataContext.PostTags <span style="color:Blue">select</span> <span style="color:Blue">new</span> {pt.Post, pt.Tag})<br/> .ToLookup(x =&gt; x.Tag, x =&gt; x.Post); </pre> </div> <br/> Why can't the Linq2SQL provider generate the right SQL in the original case and return me a meaningful lookup? By the right SQL, any SQL that would return the right Post and Tag objects and allow for grouping them correctly. <p>(As a cross-reference, here is my question on stakoverflow.com http://stackoverflow.com/questions/1724748/why-is-tolookup-dependent-on-load-options-in-linq2sql)</p> </div> </div>Thu, 19 Nov 2009 14:42:46 Z2009-11-24T00:28:39Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/53299a4a-afbb-4b22-9d60-9839809ada10http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/53299a4a-afbb-4b22-9d60-9839809ada10Aaron Clausonhttp://social.msdn.microsoft.com/Profile/en-US/?user=Aaron%20ClausonHow can the DateTime format be customised when storing in varchar<div class=post-text> <p>I use an SQL varchar field to store my datetimes and would like Linq-to-SQL to store DateTime fields using ToString(&quot;o&quot;).</p> <pre class=prettyprint><code><span class=pun></span> [Column(Name = &quot;inserted&quot;, DbType = &quot;varchar(30)&quot;, CanBeNull = false)]<br/> public DateTime Inserted { get; set; }</code> </pre> <p>A Linq-to-SQL insert will result in a format of &quot;mm/dd/yyyy HH:mm:ss&quot;. How can I specify that the datetime string format used when storing in the database should be ToString(&quot;o&quot;)?</p> <p>Thanks.</p> <p>Aaron</p> </div>Sun, 22 Nov 2009 23:21:12 Z2009-11-23T07:52:15Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/8160d92a-fde3-4811-a971-a08eb1bf57d8http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/8160d92a-fde3-4811-a971-a08eb1bf57d8McDaddy98http://social.msdn.microsoft.com/Profile/en-US/?user=McDaddy98Incorrect Query Result Set ReturnedI have a very complex Linq to SQL query that returns a result set from a Microsoft SQL Server database. The query is created using syntax similar to:<br/> <pre lang=x-vbnet>Dim db as MyDataContext = MyGetDataContextHelper() Dim qry = From rslt in db.MyView Select ColumnList If userParam1 IsNot Nothing Then qry = qry.Where(lambda for the filter) End If etc.... qry.ToList() </pre> <br/>There are several user-specified filters to the query, including one that does a geographic radius search.<br/><br/>Here's the problem. I have a break set on the &quot;ToList&quot; call right at the end. When the break is hit I use the Linq to SQL Debug Visualizer to see the generated SQL statement. I copy that complex SQL statement into a SQL Server Management Studio query window and execute it against my database to get exactly the result set I want. So the generated SQL appears to produce the desired result. However, when I execute the &quot;ToList&quot; method of the query object the list returned has fewer rows and some different rows.<br/><br/>How can that be? If the generated SQL is simply passed over the connection to the SQL Server shouldn't it generate exactly the result set I see in SQL Server Management Studio? I assume that I am misunderstanding something about the Linq to SQL mechanism, i.e. that it's not just a passthrough to SQL Server. Is that correct?<br/><br/>Thanks in advance,<br/><br/>Bob Mc.Tue, 17 Nov 2009 19:05:03 Z2009-11-23T00:40:49Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/fe4b83a5-29f9-49e9-ba12-5131646e1cf7http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/fe4b83a5-29f9-49e9-ba12-5131646e1cf7tragerhttp://social.msdn.microsoft.com/Profile/en-US/?user=tragerNew row in a cascaded DataGridViewRefering to Beth Massi's blog on the subtlties of cascading datagridViews: -<br/> http://blogs.msdn.com/bethmassi/archive/2007/10/02/linq-to-sql-and-one-to-many-relationships.aspx?CommentPosted=true#commentmessage<br/> <br/> I have Customer and Order DataGridViews with the DGVOrder datasource being based on customer. <br/> <br/> I am having trouble adding a new Order if the Customer doesn't already have an order assigned to it.<br/> <br/> The problem is caused by the fact that Order.CustomerID is only auto generated when Order table has data in it.<br/> <br/> Could anyone tell me how to get the Order.CustomerID to auto populate correctly, and elegantly, when there are no entries in the Order table?<br/> <br/> My binding code is as follows: - <br/> <br/> <div style="color:Black;background-color:White"> <pre>DC = <span style="color:Blue">New</span> DataClassesWhatToPlantDataContext DC.Log = writer CustomerList = (<span style="color:Blue">From</span> s <span style="color:Blue">In</span> DC.Customer <span style="color:Blue">Order</span> <span style="color:Blue">By</span> s.Name) CustomerBindingSource.DataSource = CustomerList CustomerDataGridView.Datasource = CustomerBindingSource OrdersDataGridView.DataSource = CustomerBindingSource OrdersDataGridView.DataMember = <span style="color:#a31515">&quot;Orders&quot;</span> </pre> </div> Many Thanks<br/> <br/> PaulFri, 20 Nov 2009 21:28:17 Z2009-11-21T11:36:10Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ab831df8-2f2d-47fc-b7d0-38fcc1c06175http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ab831df8-2f2d-47fc-b7d0-38fcc1c06175Kpbutthttp://social.msdn.microsoft.com/Profile/en-US/?user=KpbuttConverting from SQL to LINQ<span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small"><font size=2 color="#0000ff"><font size=2 color="#0000ff"> <p>Hi,<br/>I need some help translating this query to LINQ. <br/><br/>SELECT</p> </font></font></span><font size=2 color="#0000ff"> <p> </p> </font></span> <p><span style="font-size:x-small"> [t1]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[Description] </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">As</span></span><span style="font-size:x-small"> [ModelNumber]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">,</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small"> <br/></span></span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">        (</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">SELECT</span></span><span style="font-size:x-small"> [t2]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[Value] </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">FROM</span></span><span style="font-size:x-small"> [dbo]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[Client_ProductValues] </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">AS</span></span><span style="font-size:x-small"> [t2] <br/></span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">         INNER</span></span><span style="font-size:x-small"> </span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">JOIN</span></span><span style="font-size:x-small"> [dbo]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[Client_ProductAttributes] </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">AS</span></span><span style="font-size:x-small"> [p0] <br/></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">         ON</span></span><span style="font-size:x-small"> [p0]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[ClientProductAttributeID] </span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">=</span></span><span style="font-size:x-small"> [t2]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[ClientProductAttributeID] <br/></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">         WHERE </span></span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">(</span></span><span style="font-size:x-small">[p0]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[Field_Mapping] </span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">=</span></span><span style="font-size:x-small"> </span><span style="color:#ff0000;font-size:x-small"><span style="color:#ff0000;font-size:x-small">'Product_Name'</span></span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">)</span></span><span style="font-size:x-small"> </span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">AND</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small"> </span></span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">(</span></span><span style="font-size:x-small">[t1]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[ClientProductID] </span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">=</span></span><span style="font-size:x-small"> [t2]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[ClientProductID]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">)<br/></span></span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">        )</span></span><span style="font-size:x-small"> </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">AS</span></span><span style="font-size:x-small"> [DisplayName]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">,</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small"> <br/></span></span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">        (</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">SELECT</span></span><span style="font-size:x-small"> [t2]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[Value] </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">FROM</span></span><span style="font-size:x-small"> [dbo]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[Client_ProductValues] </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">AS</span></span><span style="font-size:x-small"> [t2]<br/></span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">         INNER</span></span><span style="font-size:x-small"> </span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">JOIN</span></span><span style="font-size:x-small"> [dbo]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[Client_ProductAttributes] </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">AS</span></span><span style="font-size:x-small"> [p0] <br/></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">         ON</span></span><span style="font-size:x-small"> [p0]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[ClientProductAttributeID] </span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">=</span></span><span style="font-size:x-small"> [t2]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[ClientProductAttributeID] <br/></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">         WHERE </span></span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">(</span></span><span style="font-size:x-small">[p0]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[Field_Mapping] </span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">=</span></span><span style="font-size:x-small"> </span><span style="color:#ff0000;font-size:x-small"><span style="color:#ff0000;font-size:x-small">'Model_Series_Name'</span></span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">)</span></span><span style="font-size:x-small"> </span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">AND</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small"> </span></span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">(</span></span><span style="font-size:x-small">[t1]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[ClientProductID] </span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">=</span></span><span style="font-size:x-small"> [t2]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[ClientProductID]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">)<br/></span></span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">        )</span></span><span style="font-size:x-small"> </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">AS</span></span><span style="font-size:x-small"> [DisplayName]<br/></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">FROM <br/></span></span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">        (</span></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">SELECT</span></span><span style="font-size:x-small"> [t0]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[ClientProductID]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">,</span></span><span style="font-size:x-small"> [t0]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[Description]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">,</span></span><span style="font-size:x-small"> [t0]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[OrgID] <br/></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">          FROM</span></span><span style="font-size:x-small"> [dbo]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[Client_Products] </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">AS</span></span><span style="font-size:x-small"> [t0]<br/></span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">          GROUP</span></span><span style="font-size:x-small"> </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">BY</span></span><span style="font-size:x-small"> [t0]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[ClientProductID]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">,</span></span><span style="font-size:x-small"> [t0]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[Description]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">,</span></span><span style="font-size:x-small"> [t0]</span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">.</span></span><span style="font-size:x-small">[OrgID] <br/></span><span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small">        )</span></span><span style="font-size:x-small"> </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">AS</span></span><span style="font-size:x-small"> [t1]<br/><br/>Your help is always appreciated.<br/><br/>thanks,</span></p><hr class="sig">kashifThu, 19 Nov 2009 13:38:28 Z2009-11-20T18:21:20Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/c35b5b19-5942-46b0-ad6b-c190407415dahttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/c35b5b19-5942-46b0-ad6b-c190407415daSimple Sampleshttp://social.msdn.microsoft.com/Profile/en-US/?user=Simple%20SamplesType or namespace name not foundI am using the sample code in: <a href="http://msdn.microsoft.com/en-us/library/bb399375.aspx">How to: Connect to a Database (LINQ to SQL)</a><br/><br/>I am able to compile without errors except the following compile error: <blockquote>error CS0246: The type or namespace name 'Customers' could not be found (are you missing a using directive or an assembly reference?)</blockquote> <p>The error is for the line:</p> <blockquote>public Table&lt;Customers&gt;;</blockquote> <p>I agree with the compiler; I don't see how it knows what the Customers table is. I get that error when I use the sample code that uses the Northwind class but I also get the error if I don't use the class and use code that uses GetTable.</p> <p>I apologize for asking such a simple question; I assume there is a simple answer and I need to read all about LINQ and all of that. If someone does not mind answering this question, that will help.</p><hr class="sig">Sam Hobbs; see my SimpleSamples.InfoThu, 19 Nov 2009 23:13:12 Z2009-11-20T07:15:33Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/30b21817-05f1-46b0-a7b8-3b2a14c6d9e9http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/30b21817-05f1-46b0-a7b8-3b2a14c6d9e9farsi-salmanhttp://social.msdn.microsoft.com/Profile/en-US/?user=farsi-salman'System.Web.HttpUnhandledException' was thrownHi <div><br/></div> <div>I'm facing an unknown issue, I developed an application which is working fine on local development machine but unfortunately it is fail to function. It is consume data using LINQtoSQL from two different databases, both databases are hosted on different servers. Running application on local machine gives good performance as well good result as our desire, any help will be appreciate and thanks in advance.</div> <div><br/></div> <div>Following Error I'm getting:</div> <div><br/></div> <div>Error - Data </div> <div><br/></div> <div>System.Collections.ListDictionaryInternal </div> <div> <p class=MsoNormal> </p> <p class=MsoNormal>Error - Message </p> <p class=MsoNormal>Exception of type 'System.Web.HttpUnhandledException' was thrown. </p> <p class=MsoNormal><br/> Error - Source </p> <p class=MsoNormal>System.Web <br/></p> <p class=MsoNormal>Error - Stack </p> <p class=MsoNormal>Trace at System.Web.UI.Page.HandleError(Exception e) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) at System.Web.UI.Page.ProcessRequest() at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) at System.Web.UI.Page.ProcessRequest(HttpContext context) at ASP.clients_testre_aspx.ProcessRequest(HttpContext context) in c:\windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\resources\9dcb6504\2680bc\App_Web_ceq8vnnp.4.cs:line 0 at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) </p> <p class=MsoNormal>Regards</p> <p class=MsoNormal>Salman Farsi</p> </div>Wed, 18 Nov 2009 11:41:45 Z2009-11-24T05:46:34Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/d2386b8c-21bb-4922-a93c-d95f1ad3688ehttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/d2386b8c-21bb-4922-a93c-d95f1ad3688esnorlakshttp://social.msdn.microsoft.com/Profile/en-US/?user=snorlaksling large tableHi,<br/> <br/> Im facing the problem described below.<br/> <br/> I use linq to proceed each record from table. Table contains 130 000 000 records so its quite huge. Yes  I know about Integration services but I need to use winforms for that. And I like LINQ.<br/> <br/> Ok the problem is that proceessing such a big numer of records and storing results in memory can make lack of memory problem. So that I would like to be able to proceed for example 1000 records than other day proceed another 1000 records and so on.<br/> <br/> Problem Is that on such a huge table making object.skip(1000).take(1000)  linq statement gives me a timeout excpetion.<br/> <br/> Any ideas why is it like that ?<br/> <br/> thanks for helpWed, 11 Nov 2009 18:26:08 Z2009-11-20T17:39:34Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/2a9f9f0b-9de0-481a-89ee-3502dee1484ehttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/2a9f9f0b-9de0-481a-89ee-3502dee1484eKevin Hendrikshttp://social.msdn.microsoft.com/Profile/en-US/?user=Kevin%20HendriksUnsespected behavior need help plz.I get the following error<br/><br/>Cannot insert the value NULL into column 'ProjectID', table 'dbProPlan.dbo.ProjectFase'; column does not allow nulls. INSERT fails.<br/>The statement has been terminated.<br/><br/>Wich in sense is not strange if the value would be NULL but it aint.<br/><br/>I use the following code<br/> <pre lang="x-c#">IEnumerable&lt;KHKVKBelege&gt; orderList = from order in DbKHK.KHKVKBeleges where order.Belegnummer.ToString().StartsWith(&quot;19&quot;) orderby order.Belegnummer ascending select order; foreach (KHKVKBelege order in orderList) { try { Project project = new Project() { ID = order.Belegnummer.ToString() }; if (!DbProPlan.Projects.AsEnumerable().Contains(project, new LambdaComparer&lt;Project&gt;((x, y) =&gt; x.ID.Equals(y.ID)))) { project.StartDate = (DateTime)order.Belegdatum; project.CustomerID = order.A0Empfaenger.Trim(); ProjectFase fase = new ProjectFase() { Name = &quot;Fase 1&quot; }; IEnumerable&lt;KHKVKBelegePositionen&gt; regels = from details in DbKHK.KHKVKBelegePositionens where details.BelID.Equals(order.BelID) select details; foreach (KHKVKBelegePositionen row in regels) { if (row.Artikelnummer != null) { ProjectPart projectPart = DbProPlan.ProjectParts.Single(part =&gt; part.ID.Equals(row.Artikelnummer.Trim())); ProjectItem item = null; switch (projectPart.Category) { case ProjectPartCategorys.Consultancy: item = new ProjectItemConsultancy() { NumberOfDays = Convert.ToInt32(row.Menge) }; break; case ProjectPartCategorys.Training: item = new ProjectItemTraining() { Attendees = Convert.ToInt32(row.Menge) }; break; case ProjectPartCategorys.Software: item = new ProjectItemSoftware() { Licences = Convert.ToInt32(row.Menge) }; break; default: item = new ProjectItemConsultancy() { NumberOfDays = Convert.ToInt32(row.Menge) }; break; } item.ProjectPart = projectPart; fase.ProjectItems.Add(item); } } project.ProjectFases.Add(fase); DbProPlan.Projects.InsertOnSubmit(project); DbProPlan.SubmitChanges(); } } catch (Exception e) { LogWriter.WriteLine(LogTypes.Error, string.Format(&quot;Synchronization of project with id {1} failed; {0}&quot;, e.Message, order.Belegnummer.ToString())); } }</pre> As you can see the project number is atleast '19' after that I create a fase object and add it to the collection of fases of the project. This is all fine and good. If I check the fase object it even gets the number of the project (Thanks to link to sql it does it automaticly) At the ProjectID then I add the projects to the Projects table and sumbit the changes. And I get the error, why does the ProjectID disappear from my ProjectFase?Thu, 19 Nov 2009 11:26:32 Z2009-11-25T03:26:00Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/4354fa9d-4112-4e4a-8dd3-d5609997857fhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/4354fa9d-4112-4e4a-8dd3-d5609997857fManuel Marinihttp://social.msdn.microsoft.com/Profile/en-US/?user=Manuel%20MariniExisting rows not update when I execute the query again<p>Hi,</p> <p>I've a readonly DataGridView on a form,<br/>this DataGridView should update every &lt;n&gt; seconds.</p> <p>at form level I've declared:<br/>MSGDataContext Db = new MSGDataContext();</p> <p>In the Load event of the form I use a code like this:</p> <p>Db.Log = Console.Out;<br/>var myStatus = Db.ExecuteQuery&lt;STATO_INXINVINI&gt;(SqlSelect);<br/>STATO_INXINVINIBindingSource.DataSource = myStatus;</p> <p>Insiede a timer I execute the query again and again but I've noticed that existings rows are NOT UPDATED with new values readed from the db. New rows instead are correctly added... looking at the Log the Select statement is executed every time.<br/><br/>Is it possible to update existings rows without instancing a new DataContext before calling again the select ?<br/><br/>I've noticed that there's a way to update the rows calling the resetbinding on the bindingsource but it executes a new select for each row so it's slow.<br/><br/>Similar code without LINQ (using a DataTable) works correctly (it updates the rows on the grid) but I've already defined a datacomtext including the STATO table for other purposes and I prefer not to use a dataset only to solve this problem.<br/><br/>Thank you very much every help is appreciated.</p>Wed, 18 Nov 2009 10:24:22 Z2009-11-19T09:22:08Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/6df0be14-9bb4-47e4-b8a5-26cea5508a69http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/6df0be14-9bb4-47e4-b8a5-26cea5508a69JamesChambershttp://social.msdn.microsoft.com/Profile/en-US/?user=JamesChambersSqlGeography and LINQ to SQLThere was a post a while back that suggested that the spatial types might be added to a future release of LINQ to SQL and Entities, but I'm not seeing any love in the VS 2010 Beta 2 bits.  I've got a big enough project going right now using geography types that this would really save my rump.  I can influence the data model, but for the most part it's already done.  We're using LtoS extensively and I'm hoping I can start using tables with those types in the wicked cool designer we get in VS. <div><br/></div> <div>Does anyone have any news?</div> <div><br/></div> <div>Thanks in advance!</div> <div><br/></div> <div>Cheers,</div> <div>-jc</div><hr class="sig">Me, coding and stuff: <a href="http://theycallmemrjames.blogspot.com/">Mr. James</a>Wed, 18 Nov 2009 22:31:34 Z2009-11-19T04:09:19Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/7479ea0c-7404-47d0-824a-e89c00fc52d3http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/7479ea0c-7404-47d0-824a-e89c00fc52d3John Ruskhttp://social.msdn.microsoft.com/Profile/en-US/?user=John%20Rusk64-bit problemWe are currently getting a problem on Vista 64 where certain LINQ To SQL queries lock up the machine, with 100% CPU usage.  This is in an ASP.NET application.  If we switch the application over to running as a 32-bit app (rather than 64) then the problem goes away.<br/><br/>Are there any known bugs in this regard?  Any hotfixes available or planned?<br/><br/>John<hr class="sig">John Rusk, http://dotnet.AgileKiwi.com - .NET and AgilityWed, 01 Jul 2009 23:40:28 Z2009-11-20T17:34:22Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/cea6f5e8-531b-4d42-9c5a-90e58fa6db5fhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/cea6f5e8-531b-4d42-9c5a-90e58fa6db5fdatAdrenalinehttp://social.msdn.microsoft.com/Profile/en-US/?user=datAdrenalineAdding Child entities yields an exception ... :-s<p>I am new to C# and LINQ to SQL ... I have the following entity relationships ...<br/><br/>DbCollaboration<br/>+---DbSchedule<br/>+---DbOccurrence<br/><br/>I am dumping data gathered from the web in xml for with a class hierarchy like this:<br/><br/>WbxEvent<br/>+---WbxConference<br/>+---WbxOccurrence<br/><br/>The two models emulate each other, the Linq objects are those beginning with Db.<br/><br/>I have the following code to TRY to attempt to create the objects in the Db* Entities, however I get an &quot;Object is not set to an object&quot; exception at the indicated line:<br/><br/><span style="font-size:x-small"><span style="color:#008000;font-size:x-small"><span style="color:#008000;font-size:x-small"></span></span><span style="font-size:x-small"><span style="font-size:x-small"> <p> </p> </span></span> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">foreach</span></span><span style="font-size:x-small"> (</span><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">WbxEvent</span></span><span style="font-size:x-small"> e </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">in</span></span><span style="font-size:x-small"> webexEvents) </span> <p> </p> <p><span style="color:#008000;font-size:x-small"><span style="color:#008000;font-size:x-small">    //set the collaboration data from the webex event</span></span></p> <span style="font-size:x-small"><span style="font-size:x-small"> <p> </p> </span></span> <p><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">    DbCollaboration</span></span><span style="font-size:x-small"> cb = </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">new</span></span><span style="font-size:x-small"> </span><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">DbCollaboration</span></span><span style="font-size:x-small">(e);<span style="font-size:x-small"> <p> </p> </span></span> <p> </p> <p><span style="color:#008000;font-size:x-small"><span style="color:#008000;font-size:x-small">    //get the schedules</span></span></p> <span style="font-size:x-small"><span style="font-size:x-small"> <p> </p> </span></span> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">    if</span></span><span style="font-size:x-small"> (e.Conference != </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">null</span></span><span style="font-size:x-small">) </span> <p> </p> <p><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small"><span style="color:#0000ff">        </span>DbSchedule</span></span><span style="font-size:x-small"> s = </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">new</span></span><span style="font-size:x-small"> </span><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">DbSchedule</span></span><span style="font-size:x-small">(e.Conference); </span> <p> </p> <p><span style="color:#008000;font-size:x-small"><span style="color:#008000;font-size:x-small"><span style="color:#0000ff">    </span>//get the occurrences</span></span></p> <span style="font-size:x-small"><span style="font-size:x-small"> <p> </p> </span></span> <p><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">    foreach</span></span><span style="font-size:x-small"> (</span><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">WbxConferenceHistory</span></span><span style="font-size:x-small"> h </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">in</span></span><span style="font-size:x-small"> e.History) </span> <p> </p> <p><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small"><span style="color:#0000ff">        </span>DbOccurrence</span></span><span style="font-size:x-small"> o = </span><span style="color:#0000ff;font-size:x-small"><span style="color:#0000ff;font-size:x-small">new</span></span><span style="font-size:x-small"> </span><span style="color:#2b91af;font-size:x-small"><span style="color:#2b91af;font-size:x-small">DbOccurrence</span></span><span style="font-size:x-small">(h); </span></p> <p><span style="color:#0000ff">        </span>cb.DbOccurrences.Add(o);  //&lt;&lt;&lt;-- Exception is raised here (note, the &quot;get conference&quot; portion was skipped)</p> <p><span style="color:#0000ff">    </span>}</p> <p>}<br/><br/>Any help would be appreciated.  I am unsure what would be the most helpful for evaluation of my issues, so if you need additional info, don't hesitate to ask and I will provide that information.<br/><br/>The Ex.Message is:<br/>Object reference not set to an instance of an object.</p> </p> <p><span style="color:#0000ff">    </span>{</p> <span style="font-size:x-small"> <p> </p> </span></p> <p><span style="color:#0000ff">        </span>s.DbCollaboration = cb;</p> <p><span style="color:#0000ff">        </span>cb.DbSchedules.Add(s);</p> <p><span style="color:#0000ff">    </span>}</p> <span style="font-size:x-small"> <p> </p> </span></p> <p><span style="color:#0000ff">    </span>{</p> <span style="font-size:x-small"> <p> </p> </span></p> </p> <p>{</p> <span style="font-size:x-small"> <p> </p> </span></span></p> <p>//get the web ex stuff into the database</p><hr class="sig">Brent Spaulding | Access MVPWed, 18 Nov 2009 22:38:51 Z2009-11-18T23:21:16Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/b510cc58-217c-4066-a332-eff07008be94http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/b510cc58-217c-4066-a332-eff07008be94newbie26http://social.msdn.microsoft.com/Profile/en-US/?user=newbie26Help!Hi i need some help, but i post it on the wrong section that's why i will post here the link<br/> <br/> <a href="http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/94778e18-69f7-45db-8d73-0bfd68508b76">http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/94778e18-69f7-45db-8d73-0bfd68508b76</a> <br/> <br/> <a href="http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/e1831258-0841-4fd0-9c4e-e732ae32aab2">http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/e1831258-0841-4fd0-9c4e-e732ae32aab2</a>Wed, 18 Nov 2009 10:31:24 Z2009-11-20T07:14:10Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/3186889b-6164-4233-abdc-938b6098bc80http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/3186889b-6164-4233-abdc-938b6098bc80dr_csharp_firsthttp://social.msdn.microsoft.com/Profile/en-US/?user=dr_csharp_firstident_currenthi friends<br/> i wanna retrieve last identity in SQL table with linq,in SQL i use ident_current..how can i have this in LINQ ?Mon, 16 Nov 2009 08:37:44 Z2009-11-18T08:04:34Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ba86b51d-e526-463a-b14c-907d5aa1590dhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ba86b51d-e526-463a-b14c-907d5aa1590dChui Keanhttp://social.msdn.microsoft.com/Profile/en-US/?user=Chui%20KeanNested Query<span style="color:#808080;font-size:x-small"><span style="color:#808080;font-size:x-small"><br/>SELECT * FROM ClientTbl AS C<br/>WHERE C.ID IN ( SELECT UserID FROM ClientSetTbl WHERE ID = 123 )<br/><br/><br/>How can I convert the above to LINQ? I have tried many suggestions in the web including converting the UserID into a List before the query, but unable to figure out the correct way of doing.<br/><br/>Note: The above code is extracted from a very long query. I can't change the way it works.<br/><br/>Many thanks in advance :)</span></span>Mon, 16 Nov 2009 08:02:57 Z2009-11-18T06:16:34Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/249a5347-3123-4d03-9853-67465d773beahttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/249a5347-3123-4d03-9853-67465d773beaanhansenhttp://social.msdn.microsoft.com/Profile/en-US/?user=anhansenUsing C# method in where clause or joinHi<br/> <br/> I am writing a generic framework and need some help. <br/> <br/> I have a method that on a Table&lt;TEntity&gt; select entries. The challenge is that the entries selected are depedent on other entries in a global changelog table. In this changelog entries are identified in two columns, one with the tablename, and one with the key columns in the following format, e.g [ID:123] or if multiple keycolumns exist [ID:1234][OtherID:hest]<br/> <br/> So by examining the ColumnAttributes on the properties for a table class, i can make this &quot;rowkey&quot;. All properties with columnAttribute and the IsPrimaryKey set to true is in the key.<br/> <br/> Now, when i try to something like this:<br/> <br/> Table&lt;MyTableClass&gt; table = myDataContext.GetTable&lt;MyTableClass&gt;();<br/> <br/> var rows = from row in table where CreateRowKey(row) == &quot;[ID:1234]&quot; select row;<br/> <br/> I get an System.NotSupportedException. Method CreateRowKey has no supported translation to SQL.<br/> <br/> My question is now: <br/> Are there some way i can make this method, so it translates to SQL in can be used. The result  from the function could be something like '[ID:' + row.ID + ']' that could be inserted into the TSQL generated by LINQ.<br/> <br/> I am new to LINQ, but the &quot;framework&quot; generated expressions that are evaluated to SQL, can't i input some custom SQL as well? Or do i need to generate the entire SQL and use ExecuteCommand?<br/> <br/> I hope you can figure out what im trying to do, and can provide me with some info on where to go. (Can System.Linq.Expressions solve this?)<br/> <br/> /Anders<br/> <br/> <br/> <br/> <br/>Mon, 15 Jun 2009 12:43:52 Z2009-11-18T03:57:38Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/f85daedd-9203-4026-b5c0-ea41d7a2d058http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/f85daedd-9203-4026-b5c0-ea41d7a2d058acfalcon2001http://social.msdn.microsoft.com/Profile/en-US/?user=acfalcon2001LINQ Where Clause for UII have a UI that has some date fields used to specify date ranges for results as well as a few text boxes to filter results like the contents entered in the boxes. Obviously, these fields aren't always filled in, so my where clause can have various filtering needs depending on what the user enters. Does anyone have any examples of handling this in LINQ? I use dynamic sql in other older apps but this app is already using LINQ with SQL so I was wondering if that could handle this or not.<br/><br/>Thanks,<br/>AdamTue, 17 Nov 2009 22:11:26 Z2009-11-24T05:45:02Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/11ec04c8-5acb-4db9-9112-51c67e7ee751http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/11ec04c8-5acb-4db9-9112-51c67e7ee751MrRichDeanhttp://social.msdn.microsoft.com/Profile/en-US/?user=MrRichDeanLINQ multiple where clause<p>Hello all...thicky MrDean here!!!<br/><br/>I have the following code that build a web method that is ultimately used in the good old autocompleteextender</p> <pre>TORDataContext db = new TORDataContext(); return db.tblReporting .Where(r =&amp;gt; r.UnitUserfield1.Contains(prefixText)).OrderBy(r =&amp;gt; r.UnitUserfield1).Select(r =&amp;gt; r.UnitUserfield1).Take(count).Distinct().ToArray();<br/></pre> <span style="font-family:Courier New">Now, I would like to add in another where clause into this i.e. to select a certain member within the tblReporting. I have attempted the following with no success:<br/><br/> <pre>return db.tblReporting .Where(r =&amp;gt; r.MemberId=(&quot;123&quot;) &amp;&amp;(r =&amp;gt; r.UnitUserfield1.Contains(prefixText)).OrderBy(r =&amp;gt; r.UnitUserfield1).Select(r =&amp;gt; r.UnitUserfield1).Take(count).Distinct().ToArray();</pre> Can someone point out the error in my ways - apologies for what is a simple question, I am brand spanking new to this development malarky!</span>Tue, 17 Nov 2009 13:16:53 Z2009-11-17T15:44:49Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ceda39e7-753a-4ad8-8dfa-dc885d99d133http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ceda39e7-753a-4ad8-8dfa-dc885d99d133CSevnhttp://social.msdn.microsoft.com/Profile/en-US/?user=CSevnGetting the ID from a table using LINQ to SQL?The folowing procedure is suposed to get the ID from the Author table, but I get the error, which is shown below the code snippet.  This worked when I used an int instead of string, but with string it doesn't work.  I have to use string, because the AuthorID is generated using text.<br/> <pre lang="x-c#">public void GetAuthorID() { string[] myList = new string[10]; var query = from au in myDb.Author where au.AuthorName == mAuthorName select au.AuthorID; myList = query.ToArray; mAuthorID = myList[0]; }//End proc</pre> <br/> Cannot convert method group 'ToArray' to non-delegate type 'string[]'. Did you intend to invoke the method?    E:\Visual Studio Projects\SILibraryProject\Application\SmalLib\BusinessLogic\BusinessLogic\clsAuthorBL.cs    91    22    SmalLibBL<br/>Tue, 17 Nov 2009 11:21:52 Z2009-11-17T14:08:39Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/10abca60-0d3e-45d9-8e0a-da5dd8ffb83bhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/10abca60-0d3e-45d9-8e0a-da5dd8ffb83bserdarverihttp://social.msdn.microsoft.com/Profile/en-US/?user=serdarveriSearch in the If s<div dir=ltr>Hi Friends, <br/> Search engine to use SQL working.Linq to my query. <br/> Search engine also different search options to filter yapıyor.Dolaysıyla search engine olacak.Benim (<a href="http://picasaweb.google.com.tr/lh/photo/RHBaK1nB1Y_SNcgzY7p3cg?authkey=Gv1sRgCNyhxKfvl5vqfg&amp;feat=directlink">picture</a> ) 2 one DropDownList, 4 RadioButton, TextBox and the TextBox in the keyword input have Ajax caledarler. <br/> This problem friends, <br/> Users will try different combinations on different search engines. (For example, only the category list selected keyword was entered and the city searching for a combination of these ...) <br/> I like these control conditions and to provide if working.Dolaysıyla is too long. (<a href="http://www.pasteninja.com/paste/xb19">Code here</a> ) <br/> I'm looking to remedy this, friends. <br/> Waiting for your ideas. <br/> Goodbye ....</div>Tue, 10 Nov 2009 17:02:40 Z2009-11-18T02:06:26Zhttp://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ae8d1c6e-3fa3-431d-bed9-7d6dc5931af3http://social.msdn.microsoft.com/Forums/en-US/linqtosql/thread/ae8d1c6e-3fa3-431d-bed9-7d6dc5931af3Michal Rostoker1http://social.msdn.microsoft.com/Profile/en-US/?user=Michal%20Rostoker1DataBinding - Please help me!! i already posted this and nobody answered<p class=MsoNormal style="direction:ltr;unicode-bidi:embed;text-align:left" dir=ltr><span style="font-size:xx-small;color:#000000;font-family:Verdana"><span style="font-size:8pt;color:black;font-family:Verdana">hi<br/>i have a windows application.<br/>i have a user interface which present data from database, create data from user input that will be added to databse through the application etc'.<br/>i have 2 question:<br/>1) i know that in ADO.net i can use dataset and define to the dataset insert, update and delete statement. i can display values with the dataset on grid, i can allow user edit the values and they will be updated on database with no effort by my side. is there a way to do something like that with linq? i know that i can bind table to grid, for example, as the data source but i couldnt succedd binding 2 tables with relations (one has a foreign key from the other) on grid. is there a way to do this? how can i use tables with relation and display the relation? <br/>in addition i tried binding one table to grid, edit values and than use submit changes function but the data in database is not being updated. is there a way doing that? again, its simple in ado.net but i couldnt find it in linq so i do all of the work by myself<br/>2) i have a stored procedure which retrieve data from some tables. i display it on grid. user do actions on that and create an entity which i need to insert to database. what is the correct way to work in such case? i am creating my own object of type that is very much like the dbml table (or the database table) that i want to insert the data into. after ceating the object and populating it i transfer the object to the data context layer, create object of the database table type, populate it with the data from the object and insert to database - this is a lot of work. i work like that because it seems to me incorrect to work with tables type of the database in a higher level than the data context layer. is this conccept correct? what is the best way to work in the described example?</span></span><span style="font-size:x-small;color:#800080;font-family:Comic Sans MS"><span style="font-size:10pt;color:purple;font-family:'Comic Sans MS'"></span></span></p>Thu, 12 Nov 2009 09:35:18 Z2009-11-19T02:34:52Z