<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: LINQ to SQL and tables with no Primary Key</title>
	<atom:link href="http://www.i-think22.net/archives/2009/07/24/linq-to-sql-and-tables-with-no-primary-key/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.i-think22.net/archives/2009/07/24/linq-to-sql-and-tables-with-no-primary-key/</link>
	<description>Now with more rambling</description>
	<lastBuildDate>Wed, 16 Jun 2010 01:11:44 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Rhys</title>
		<link>http://www.i-think22.net/archives/2009/07/24/linq-to-sql-and-tables-with-no-primary-key/comment-page-1/#comment-8744</link>
		<dc:creator>Rhys</dc:creator>
		<pubDate>Fri, 28 Aug 2009 20:55:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.i-think22.net/archives/2009/07/24/linq-to-sql-and-tables-with-no-primary-key/#comment-8744</guid>
		<description>LINQ to entities is a different beast. While I&#039;m pretty sure they have a lot in common this isn&#039;t something I know much about. My guess would be that if you can express your query in LINQ it will work out what SQL is necessary to execute the query.

Of course if you have a very specific query you need to run, consider creating a stored procedure on your database. (LINQ to SQL can handle these well, and I&#039;m sure the story is similar with LINQ to Entities).</description>
		<content:encoded><![CDATA[<p>LINQ to entities is a different beast. While I&#8217;m pretty sure they have a lot in common this isn&#8217;t something I know much about. My guess would be that if you can express your query in LINQ it will work out what SQL is necessary to execute the query.</p>
<p>Of course if you have a very specific query you need to run, consider creating a stored procedure on your database. (LINQ to SQL can handle these well, and I&#8217;m sure the story is similar with LINQ to Entities).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brijesh</title>
		<link>http://www.i-think22.net/archives/2009/07/24/linq-to-sql-and-tables-with-no-primary-key/comment-page-1/#comment-8743</link>
		<dc:creator>Brijesh</dc:creator>
		<pubDate>Thu, 27 Aug 2009 07:11:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.i-think22.net/archives/2009/07/24/linq-to-sql-and-tables-with-no-primary-key/#comment-8743</guid>
		<description>Hi,

Thanks for your response. one another query left/right outer join is possible in linq to entities ?.  if not so is there any another way out for this. plz.

Regards
Brijesh</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>Thanks for your response. one another query left/right outer join is possible in linq to entities ?.  if not so is there any another way out for this. plz.</p>
<p>Regards<br />
Brijesh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rhys</title>
		<link>http://www.i-think22.net/archives/2009/07/24/linq-to-sql-and-tables-with-no-primary-key/comment-page-1/#comment-8742</link>
		<dc:creator>Rhys</dc:creator>
		<pubDate>Tue, 25 Aug 2009 21:16:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.i-think22.net/archives/2009/07/24/linq-to-sql-and-tables-with-no-primary-key/#comment-8742</guid>
		<description>If it is urgent, &lt;strong&gt;define a primary key&lt;/strong&gt;. The alternative is to temporarily embed your own SQL logic into your code. This is not a good alternative (and if you don&#039;t do it right you can expose yourself to &lt;em&gt;SQL injection vulnerabilities&lt;/em&gt;). The following workaround is not in any way recommended:

Using the partial class for your object, add a &lt;code class=&quot;prettyprint&quot;&gt;SubmitChanges(DataContext)&lt;/code&gt; method. The &lt;code class=&quot;prettyprint&quot;&gt;DataContext&lt;/code&gt; class provides a useful &lt;code class=&quot;prettyprint&quot;&gt;ExecuteCommand(string, params object[])&lt;/code&gt; method. You can use this to execute a SQL command directly against your connection. Do not build a SQL string by concatenating the required bits together. Place all your parameters in the &lt;code class=&quot;prettyprint&quot;&gt;params&lt;/code&gt; portion of the method call. Here&#039;s an example for the class above:

&lt;pre class=&quot;prettyprint&quot;&gt;public partial class SimpleRecord
{
   public void SubmitChanges(DataContext db)
   {
      db.ExecuteCommand(@&quot;UPDATE [dbo].[SimpleTable]
         SET [value] = {0}
         WHERE [identifier] = {1}&quot;,
         this.Value, this.Identifier);
   }
}
&lt;/pre&gt;

You will likely want to wrap some exception handling around that. By using the &lt;code class=&quot;prettyprint&quot;&gt;String.Format&lt;/code&gt; style in your command you are not simply substituting the values into your query. Instead you are building a parameterized query (e.g. {0} would be replaced with @p0). This way you are still separating the the data from the command.

But finally, &lt;strong&gt;define a primary key&lt;/strong&gt;. Your database table should have one anyway.</description>
		<content:encoded><![CDATA[<p>If it is urgent, <strong>define a primary key</strong>. The alternative is to temporarily embed your own SQL logic into your code. This is not a good alternative (and if you don&#8217;t do it right you can expose yourself to <em>SQL injection vulnerabilities</em>). The following workaround is not in any way recommended:</p>
<p>Using the partial class for your object, add a <code class="prettyprint">SubmitChanges(DataContext)</code> method. The <code class="prettyprint">DataContext</code> class provides a useful <code class="prettyprint">ExecuteCommand(string, params object[])</code> method. You can use this to execute a SQL command directly against your connection. Do not build a SQL string by concatenating the required bits together. Place all your parameters in the <code class="prettyprint">params</code> portion of the method call. Here&#8217;s an example for the class above:</p>
<pre class="prettyprint">public partial class SimpleRecord
{
   public void SubmitChanges(DataContext db)
   {
      db.ExecuteCommand(@"UPDATE [dbo].[SimpleTable]
         SET [value] = {0}
         WHERE [identifier] = {1}",
         this.Value, this.Identifier);
   }
}
</pre>
<p>You will likely want to wrap some exception handling around that. By using the <code class="prettyprint">String.Format</code> style in your command you are not simply substituting the values into your query. Instead you are building a parameterized query (e.g. {0} would be replaced with @p0). This way you are still separating the the data from the command.</p>
<p>But finally, <strong>define a primary key</strong>. Your database table should have one anyway.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brijesh</title>
		<link>http://www.i-think22.net/archives/2009/07/24/linq-to-sql-and-tables-with-no-primary-key/comment-page-1/#comment-8740</link>
		<dc:creator>Brijesh</dc:creator>
		<pubDate>Tue, 25 Aug 2009 09:27:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.i-think22.net/archives/2009/07/24/linq-to-sql-and-tables-with-no-primary-key/#comment-8740</guid>
		<description>hi,

i am having the same scenario where in a table there is no primary key.
In above suggested blog add a primary key in table but is there any othere wayout where without adding a new entity as primary key.
its urgent.
Thanks
brijesh</description>
		<content:encoded><![CDATA[<p>hi,</p>
<p>i am having the same scenario where in a table there is no primary key.<br />
In above suggested blog add a primary key in table but is there any othere wayout where without adding a new entity as primary key.<br />
its urgent.<br />
Thanks<br />
brijesh</p>
]]></content:encoded>
	</item>
</channel>
</rss>
