<?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: How to Update Data with LINQ-to-SQL</title>
	<atom:link href="http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/</link>
	<description></description>
	<lastBuildDate>Thu, 29 Sep 2011 17:23:04 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Kevin</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-6696</link>
		<dc:creator>Kevin</dc:creator>
		<pubDate>Thu, 29 Sep 2011 17:23:04 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-6696</guid>
		<description>soo You need to check if the Sync Property of your table is not &quot;Always&quot; in order to the command works fine :D</description>
		<content:encoded><![CDATA[<p>soo You need to check if the Sync Property of your table is not &#8220;Always&#8221; in order to the command works fine <img src='http://www.richardbushnell.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bacx</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-5081</link>
		<dc:creator>Bacx</dc:creator>
		<pubDate>Thu, 14 Jul 2011 09:22:22 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-5081</guid>
		<description>Thx for the tutorial :)</description>
		<content:encoded><![CDATA[<p>Thx for the tutorial <img src='http://www.richardbushnell.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-2186</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Mon, 14 Feb 2011 20:41:31 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-2186</guid>
		<description>I hope this helps someone, I spent a good 3 hours finding a way to update values without doing the manual
table.myfield = &quot;newvalue&quot;
submitchanges()</description>
		<content:encoded><![CDATA[<p>I hope this helps someone, I spent a good 3 hours finding a way to update values without doing the manual<br />
table.myfield = &#8220;newvalue&#8221;<br />
submitchanges()</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-2185</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Mon, 14 Feb 2011 20:39:40 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-2185</guid>
		<description>This is my way. 

FL is a table, FLBackup is also a table, same record. 
lets say I change FL some field values but I dont know what the field names are and I want to revert back to the original field values, even after a submitchanges has been done, as long as I keep FLBackup cached it can be done, which bascially keep the same PK and does an UPDATE


 var cols = fl.GetType().GetProperties().Select(p =&gt;
                            new
                            {
                                Prop = p,
                                Attr = (ColumnAttribute)p.GetCustomAttributes(typeof(ColumnAttribute), true)
                                .SingleOrDefault()
                            }).Where(p =&gt; p.Attr != null &amp;&amp; !p.Attr.IsDbGenerated);

                        foreach (var col in cols)
                        {
                            col.Prop.SetValue(fl, col.Prop.GetValue(flbackup, null), null);
                        }
Result:
_gDBContext.GetChangeSet()
{Inserts: 0, Deletes: 0, Updates: 1}
    Deletes: Count = 0
    Inserts: Count = 0
    Updates: Count = 1</description>
		<content:encoded><![CDATA[<p>This is my way. </p>
<p>FL is a table, FLBackup is also a table, same record.<br />
lets say I change FL some field values but I dont know what the field names are and I want to revert back to the original field values, even after a submitchanges has been done, as long as I keep FLBackup cached it can be done, which bascially keep the same PK and does an UPDATE</p>
<p> var cols = fl.GetType().GetProperties().Select(p =&gt;<br />
                            new<br />
                            {<br />
                                Prop = p,<br />
                                Attr = (ColumnAttribute)p.GetCustomAttributes(typeof(ColumnAttribute), true)<br />
                                .SingleOrDefault()<br />
                            }).Where(p =&gt; p.Attr != null &amp;&amp; !p.Attr.IsDbGenerated);</p>
<p>                        foreach (var col in cols)<br />
                        {<br />
                            col.Prop.SetValue(fl, col.Prop.GetValue(flbackup, null), null);<br />
                        }<br />
Result:<br />
_gDBContext.GetChangeSet()<br />
{Inserts: 0, Deletes: 0, Updates: 1}<br />
    Deletes: Count = 0<br />
    Inserts: Count = 0<br />
    Updates: Count = 1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nilesh</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-2015</link>
		<dc:creator>Nilesh</dc:creator>
		<pubDate>Tue, 01 Feb 2011 12:45:44 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-2015</guid>
		<description>using (var context = new RegistrationByLinqEntities())
{
var valtemp = context.FornDatas.SingleOrDefault(a =&gt; a.id == id);
valtemp.Approve = app;
valtemp.CreateDate = DateTime.Now;
context.SaveChanges();
}</description>
		<content:encoded><![CDATA[<p>using (var context = new RegistrationByLinqEntities())<br />
{<br />
var valtemp = context.FornDatas.SingleOrDefault(a =&gt; a.id == id);<br />
valtemp.Approve = app;<br />
valtemp.CreateDate = DateTime.Now;<br />
context.SaveChanges();<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rafat</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-396</link>
		<dc:creator>Rafat</dc:creator>
		<pubDate>Mon, 07 Jun 2010 11:59:42 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-396</guid>
		<description>I can only say one thing..that your post is the best:)</description>
		<content:encoded><![CDATA[<p>I can only say one thing..that your post is the best:)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: NeoZ</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-339</link>
		<dc:creator>NeoZ</dc:creator>
		<pubDate>Fri, 14 May 2010 19:15:46 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-339</guid>
		<description>#24 is the same as the example at the top. I don&#039;t see how this can work. Typically you will display the data, receive changes, then save the changes. This doesn&#039;t appear to allow for changes. When you include the changes it won&#039;t work that way.</description>
		<content:encoded><![CDATA[<p>#24 is the same as the example at the top. I don&#8217;t see how this can work. Typically you will display the data, receive changes, then save the changes. This doesn&#8217;t appear to allow for changes. When you include the changes it won&#8217;t work that way.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ved</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-218</link>
		<dc:creator>Ved</dc:creator>
		<pubDate>Sat, 13 Mar 2010 04:51:48 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-218</guid>
		<description>LINQ does not suck , you just do not know it.

Make sure to do db.Table.Single(query) only then update works. 

if you do db.Table.First(query) and perform submitchange() then it will not update value. Below code works and being used in production


Database db = new Database();
Table t = db.Table.single(p=&gt;p.Column == ColumnName )
t.ColumnNameValue = value;

db.submitchanges();

thats it.</description>
		<content:encoded><![CDATA[<p>LINQ does not suck , you just do not know it.</p>
<p>Make sure to do db.Table.Single(query) only then update works. </p>
<p>if you do db.Table.First(query) and perform submitchange() then it will not update value. Below code works and being used in production</p>
<p>Database db = new Database();<br />
Table t = db.Table.single(p=&gt;p.Column == ColumnName )<br />
t.ColumnNameValue = value;</p>
<p>db.submitchanges();</p>
<p>thats it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Real programmer</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-101</link>
		<dc:creator>Real programmer</dc:creator>
		<pubDate>Thu, 10 Dec 2009 09:04:05 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-101</guid>
		<description>LINQ just sucks, don&#039;t use it! It&#039;s slow and inflexible.

It&#039;s a trap to lure people away from real programming into M$ proprietary crap.

Stick to SQL and you can work on every platform, not just M$</description>
		<content:encoded><![CDATA[<p>LINQ just sucks, don&#8217;t use it! It&#8217;s slow and inflexible.</p>
<p>It&#8217;s a trap to lure people away from real programming into M$ proprietary crap.</p>
<p>Stick to SQL and you can work on every platform, not just M$</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pure Krome</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-100</link>
		<dc:creator>Pure Krome</dc:creator>
		<pubDate>Mon, 26 Oct 2009 10:45:04 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-100</guid>
		<description>Oops -&gt; i have an error in the following sentence above.

&quot;which is what is happening in Dinesh’s example code, above).&quot;

should read as

&quot;which is what is happening in Richard Bushnell&#039;s example code, above).&quot;</description>
		<content:encoded><![CDATA[<p>Oops -&gt; i have an error in the following sentence above.</p>
<p>&#8220;which is what is happening in Dinesh’s example code, above).&#8221;</p>
<p>should read as</p>
<p>&#8220;which is what is happening in Richard Bushnell&#8217;s example code, above).&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pure Krome</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-99</link>
		<dc:creator>Pure Krome</dc:creator>
		<pubDate>Mon, 26 Oct 2009 10:43:31 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-99</guid>
		<description>Folks, Christian Zangl post above is the correct answer IMO.

By default, Linq to Sql uses Optimistic Concurrency (aka. O.C.). Everyone knows that and we&#039;re all not disputing that.

So _BY DEFINITION_ this means that we _cannot_ update our object UNLESS we know it&#039;s the same version in the database - otherwise we need to throw an exception. That&#039;s what O.C. is all about.

So -&gt; Linq to Sql does this in two ways.
1) If you have a TIMESTAMP field in the table, then send that across the wire along with the Primary Key and make sure that the current object&#039;s TIMESTAMP field (that is about to be updated) is the same as the DB&#039;s.

-or-

2) No timestamp? then we need to check -each- field (which is what is happening in Dinesh&#039;s example code, above).

So ... maybe you don&#039;t want O.C. then?! If you _want_ to make sure that the data you&#039;re about to update IS not more recent that the version in the code, then yes .. u need O.C. Otherwise, don&#039;t do Optimistic Concurrency and therefore all these hacks to get around it.

To not use O.C., make sure each field in the table that is being updated, the &#039;Update Status&#039; field is set to NEVER. The default is Always ... so switch it over to NEVER.

As is said, Christian Zangl has said it perfectly right, above.

Good Luck!</description>
		<content:encoded><![CDATA[<p>Folks, Christian Zangl post above is the correct answer IMO.</p>
<p>By default, Linq to Sql uses Optimistic Concurrency (aka. O.C.). Everyone knows that and we&#8217;re all not disputing that.</p>
<p>So _BY DEFINITION_ this means that we _cannot_ update our object UNLESS we know it&#8217;s the same version in the database &#8211; otherwise we need to throw an exception. That&#8217;s what O.C. is all about.</p>
<p>So -&gt; Linq to Sql does this in two ways.<br />
1) If you have a TIMESTAMP field in the table, then send that across the wire along with the Primary Key and make sure that the current object&#8217;s TIMESTAMP field (that is about to be updated) is the same as the DB&#8217;s.</p>
<p>-or-</p>
<p>2) No timestamp? then we need to check -each- field (which is what is happening in Dinesh&#8217;s example code, above).</p>
<p>So &#8230; maybe you don&#8217;t want O.C. then?! If you _want_ to make sure that the data you&#8217;re about to update IS not more recent that the version in the code, then yes .. u need O.C. Otherwise, don&#8217;t do Optimistic Concurrency and therefore all these hacks to get around it.</p>
<p>To not use O.C., make sure each field in the table that is being updated, the &#8216;Update Status&#8217; field is set to NEVER. The default is Always &#8230; so switch it over to NEVER.</p>
<p>As is said, Christian Zangl has said it perfectly right, above.</p>
<p>Good Luck!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: saman</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-98</link>
		<dc:creator>saman</dc:creator>
		<pubDate>Sat, 05 Sep 2009 13:10:56 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-98</guid>
		<description>sorry, i have a table that  name is  &quot;table1&quot;
and it has 3 fields, id,name and family and id is primary key
when i use this code to update table, i have this error
my code:
            int SelectedId = 5;
            var Query = (from P in bank.Table1
                         where P.id == SelectedId
                         select P).Single();
            Queryid = 0;
            Query.name = &quot;change&quot;;
            Query.famil = &quot;change&quot;;
            bank.SubmitChanges();
my error:
Can&#039;t perform Create, Update or Delete operations on &#039;Table(Table1)&#039; because it has no primary key.</description>
		<content:encoded><![CDATA[<p>sorry, i have a table that  name is  &#8220;table1&#8243;<br />
and it has 3 fields, id,name and family and id is primary key<br />
when i use this code to update table, i have this error<br />
my code:<br />
            int SelectedId = 5;<br />
            var Query = (from P in bank.Table1<br />
                         where P.id == SelectedId<br />
                         select P).Single();<br />
            Queryid = 0;<br />
            Query.name = &#8220;change&#8221;;<br />
            Query.famil = &#8220;change&#8221;;<br />
            bank.SubmitChanges();<br />
my error:<br />
Can&#8217;t perform Create, Update or Delete operations on &#8216;Table(Table1)&#8217; because it has no primary key.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mr. A</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-97</link>
		<dc:creator>Mr. A</dc:creator>
		<pubDate>Wed, 15 Jul 2009 20:39:25 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-97</guid>
		<description>For all these answers, I keep getting Cannot attach an entity that already exists.

Somebody want to explain why an update would cause that error and how to correct it?</description>
		<content:encoded><![CDATA[<p>For all these answers, I keep getting Cannot attach an entity that already exists.</p>
<p>Somebody want to explain why an update would cause that error and how to correct it?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Amr Ellafi</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-96</link>
		<dc:creator>Amr Ellafi</dc:creator>
		<pubDate>Sat, 11 Jul 2009 23:06:56 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-96</guid>
		<description>@Bruno: your solution works !</description>
		<content:encoded><![CDATA[<p>@Bruno: your solution works !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Drako</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-95</link>
		<dc:creator>Drako</dc:creator>
		<pubDate>Tue, 31 Mar 2009 13:09:55 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-95</guid>
		<description>This is my class DBMaintenance - all works fine

 public object Insert(object item)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                ITable itbl = DataContext.GetTable(item.GetType());
                itbl.InsertOnSubmit(item);
                itbl.Context.SubmitChanges();
                ts.Complete();
            }
            return item;
        }
        public object Delete(object item)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                ITable itbl = DataContext.GetTable(item.GetType());
                itbl.DeleteOnSubmit(item);
                itbl.Context.SubmitChanges();
                ts.Complete();
            }
            return item;
        }

        public object Update(object item)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                ITable itbl = DataContext.GetTable(item.GetType());
                itbl.Attach(item);
                itbl.Context.Refresh(RefreshMode.KeepCurrentValues, item);
                itbl.Context.SubmitChanges();
                ts.Complete();
            }
            return item;
        }</description>
		<content:encoded><![CDATA[<p>This is my class DBMaintenance &#8211; all works fine</p>
<p> public object Insert(object item)<br />
        {<br />
            using (TransactionScope ts = new TransactionScope())<br />
            {<br />
                ITable itbl = DataContext.GetTable(item.GetType());<br />
                itbl.InsertOnSubmit(item);<br />
                itbl.Context.SubmitChanges();<br />
                ts.Complete();<br />
            }<br />
            return item;<br />
        }<br />
        public object Delete(object item)<br />
        {<br />
            using (TransactionScope ts = new TransactionScope())<br />
            {<br />
                ITable itbl = DataContext.GetTable(item.GetType());<br />
                itbl.DeleteOnSubmit(item);<br />
                itbl.Context.SubmitChanges();<br />
                ts.Complete();<br />
            }<br />
            return item;<br />
        }</p>
<p>        public object Update(object item)<br />
        {<br />
            using (TransactionScope ts = new TransactionScope())<br />
            {<br />
                ITable itbl = DataContext.GetTable(item.GetType());<br />
                itbl.Attach(item);<br />
                itbl.Context.Refresh(RefreshMode.KeepCurrentValues, item);<br />
                itbl.Context.SubmitChanges();<br />
                ts.Complete();<br />
            }<br />
            return item;<br />
        }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Damian</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-94</link>
		<dc:creator>Damian</dc:creator>
		<pubDate>Tue, 13 Jan 2009 22:12:27 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-94</guid>
		<description>Pessoa p2 = new Pessoa();
p2.Id = 1;
p2.Nome = “Teste” + DateTime.Now.ToString();

DbContext.Pessoas.Attach(p2);
DbContext.Refresh(RefreshMode.KeepCurrentValues, p2);
DbContext.SubmitChanges();

It&#039;s works.</description>
		<content:encoded><![CDATA[<p>Pessoa p2 = new Pessoa();<br />
p2.Id = 1;<br />
p2.Nome = “Teste” + DateTime.Now.ToString();</p>
<p>DbContext.Pessoas.Attach(p2);<br />
DbContext.Refresh(RefreshMode.KeepCurrentValues, p2);<br />
DbContext.SubmitChanges();</p>
<p>It&#8217;s works.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Param Iyer</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-93</link>
		<dc:creator>Param Iyer</dc:creator>
		<pubDate>Sun, 23 Nov 2008 05:07:41 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-93</guid>
		<description>I could not find a solution to this problem for almost 5 hours before stumbling down here and writing the below piece of code...

Pessoa p2 = new Pessoa();
p2.Id = 1;
p2.Nome = “Teste” + DateTime.Now.ToString();

DbContext.Pessoas.Attach(p2);
DbContext.Refresh(RefreshMode.KeepCurrentValues, p2);
DbContext.SubmitChanges();

this thing does WORK</description>
		<content:encoded><![CDATA[<p>I could not find a solution to this problem for almost 5 hours before stumbling down here and writing the below piece of code&#8230;</p>
<p>Pessoa p2 = new Pessoa();<br />
p2.Id = 1;<br />
p2.Nome = “Teste” + DateTime.Now.ToString();</p>
<p>DbContext.Pessoas.Attach(p2);<br />
DbContext.Refresh(RefreshMode.KeepCurrentValues, p2);<br />
DbContext.SubmitChanges();</p>
<p>this thing does WORK</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Montgomery</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-92</link>
		<dc:creator>Martin Montgomery</dc:creator>
		<pubDate>Tue, 28 Oct 2008 15:58:04 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-92</guid>
		<description>Just a quick piece of code to do a general update on all records

private Product UpdateSomething(Product product)
{
    product.value = 99;
    return product;
}

public void UpdateAll()
{
    var list = (from product in DataContext.GetTable()
                    select UpdateSomething(product)).ToList();

    DataContext.SubmitChanges();
}

We can also include a where clause to filter those products being updated</description>
		<content:encoded><![CDATA[<p>Just a quick piece of code to do a general update on all records</p>
<p>private Product UpdateSomething(Product product)<br />
{<br />
    product.value = 99;<br />
    return product;<br />
}</p>
<p>public void UpdateAll()<br />
{<br />
    var list = (from product in DataContext.GetTable()<br />
                    select UpdateSomething(product)).ToList();</p>
<p>    DataContext.SubmitChanges();<br />
}</p>
<p>We can also include a where clause to filter those products being updated</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: anil</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-91</link>
		<dc:creator>anil</dc:creator>
		<pubDate>Sat, 25 Oct 2008 13:19:56 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-91</guid>
		<description>Hi I have tested with following code but didn&#039;t worked

Pessoa p2 = new Pessoa();
p2.Id = 1;
p2.Nome = “Teste” + DateTime.Now.ToString();

DbContext.Pessoas.Attach(p2);
DbContext.Refresh(RefreshMode.KeepCurrentValues, p2);
DbContext.SubmitChanges();

this way, only chances are updated.

Can someone let me know whether its possible</description>
		<content:encoded><![CDATA[<p>Hi I have tested with following code but didn&#8217;t worked</p>
<p>Pessoa p2 = new Pessoa();<br />
p2.Id = 1;<br />
p2.Nome = “Teste” + DateTime.Now.ToString();</p>
<p>DbContext.Pessoas.Attach(p2);<br />
DbContext.Refresh(RefreshMode.KeepCurrentValues, p2);<br />
DbContext.SubmitChanges();</p>
<p>this way, only chances are updated.</p>
<p>Can someone let me know whether its possible</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sorry Guys &#187; Looking for a better way to update entity</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-90</link>
		<dc:creator>Sorry Guys &#187; Looking for a better way to update entity</dc:creator>
		<pubDate>Thu, 09 Oct 2008 11:47:59 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-90</guid>
		<description>[...] ลองนึกดูว่าถ้ามี Property เยอะ ๆ แล้วจะเกิดอะไรขึ้น หากมีการแก้ไขคงมึนไม่น้อย ลอง Google ดู ก็พบว่ามีคนทำวิธีแบบนี้ด้วย http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/ [...]</description>
		<content:encoded><![CDATA[<p>[...] ลองนึกดูว่าถ้ามี Property เยอะ ๆ แล้วจะเกิดอะไรขึ้น หากมีการแก้ไขคงมึนไม่น้อย ลอง Google ดู ก็พบว่ามีคนทำวิธีแบบนี้ด้วย <a href="http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/" rel="nofollow">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bjarne Pedersen</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-89</link>
		<dc:creator>Bjarne Pedersen</dc:creator>
		<pubDate>Mon, 06 Oct 2008 15:25:56 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-89</guid>
		<description>Well, why not just use:

            if(val.recordId == 0){
                db.GrandPrixValues.InsertOnSubmit(val);
            }
            db.SubmitChanges();

Thats working and way more easy!</description>
		<content:encoded><![CDATA[<p>Well, why not just use:</p>
<p>            if(val.recordId == 0){<br />
                db.GrandPrixValues.InsertOnSubmit(val);<br />
            }<br />
            db.SubmitChanges();</p>
<p>Thats working and way more easy!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Christian Zangl</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-88</link>
		<dc:creator>Christian Zangl</dc:creator>
		<pubDate>Fri, 01 Aug 2008 09:28:21 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-88</guid>
		<description>If you go to your database.dbml and change the &quot;Update Check&quot; property on the Product fields to &quot;Never&quot; then your code will work and you&#039;ll get the SQL you wanted:

var product = new Product();
product.ProductID = 1;
Products.Attach(product);
product.Name = &quot;Richard’s product&quot;;
SubmitChanges();</description>
		<content:encoded><![CDATA[<p>If you go to your database.dbml and change the &#8220;Update Check&#8221; property on the Product fields to &#8220;Never&#8221; then your code will work and you&#8217;ll get the SQL you wanted:</p>
<p>var product = new Product();<br />
product.ProductID = 1;<br />
Products.Attach(product);<br />
product.Name = &#8220;Richard’s product&#8221;;<br />
SubmitChanges();</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mickey Mouse</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-87</link>
		<dc:creator>Mickey Mouse</dc:creator>
		<pubDate>Fri, 27 Jun 2008 00:21:33 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-87</guid>
		<description>With NHibernate you just create an instance of the entity, change the fields desired then call the Save method, done!</description>
		<content:encoded><![CDATA[<p>With NHibernate you just create an instance of the entity, change the fields desired then call the Save method, done!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard Bushnell</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-86</link>
		<dc:creator>Richard Bushnell</dc:creator>
		<pubDate>Thu, 29 May 2008 07:18:29 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-86</guid>
		<description>Hi Neal,

Changeset.Dump() is something that only works in LinqPad.

 - The changeset is generated from the DataContext, but in LinqPad, you don&#039;t reference the DataContext, because you are actually inside it.

- Dump() is a LinqPad method defined as an extension method on Object. It is LinqPad specific.

If you want more information about LinqPad, you can contact the authors at www.linqpad.net. When I contacted them, they were very helpful. I&#039;m sure they&#039;d let you know how it works.

HTH,
Richard</description>
		<content:encoded><![CDATA[<p>Hi Neal,</p>
<p>Changeset.Dump() is something that only works in LinqPad.</p>
<p> &#8211; The changeset is generated from the DataContext, but in LinqPad, you don&#8217;t reference the DataContext, because you are actually inside it.</p>
<p>- Dump() is a LinqPad method defined as an extension method on Object. It is LinqPad specific.</p>
<p>If you want more information about LinqPad, you can contact the authors at <a href="http://www.linqpad.net" rel="nofollow">http://www.linqpad.net</a>. When I contacted them, they were very helpful. I&#8217;m sure they&#8217;d let you know how it works.</p>
<p>HTH,<br />
Richard</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Neal Walters</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-85</link>
		<dc:creator>Neal Walters</dc:creator>
		<pubDate>Wed, 28 May 2008 21:57:06 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-85</guid>
		<description>How does your changeset.Dump() work?
Thanks,
Neal</description>
		<content:encoded><![CDATA[<p>How does your changeset.Dump() work?<br />
Thanks,<br />
Neal</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: TUAN</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-84</link>
		<dc:creator>TUAN</dc:creator>
		<pubDate>Tue, 06 May 2008 00:31:18 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-84</guid>
		<description>I had spend 2 hours to find the way to use Update in LINQ, and now, I want to thanks u about this article
----
Nice article, thanks u alot!</description>
		<content:encoded><![CDATA[<p>I had spend 2 hours to find the way to use Update in LINQ, and now, I want to thanks u about this article<br />
&#8212;-<br />
Nice article, thanks u alot!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard Bushnell</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-83</link>
		<dc:creator>Richard Bushnell</dc:creator>
		<pubDate>Thu, 01 May 2008 05:59:44 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-83</guid>
		<description>@Bruno:

That looks interesting, but doesn&#039;t it really do the same as doing a select before an update?</description>
		<content:encoded><![CDATA[<p>@Bruno:</p>
<p>That looks interesting, but doesn&#8217;t it really do the same as doing a select before an update?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bruno Kenj</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-82</link>
		<dc:creator>Bruno Kenj</dc:creator>
		<pubDate>Thu, 01 May 2008 02:35:49 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-82</guid>
		<description>Pessoa p2 = new Pessoa();
            p2.Id = 1;
            p2.Nome = &quot;Teste&quot; + DateTime.Now.ToString();

            DbContext.Pessoas.Attach(p2);
            DbContext.Refresh(RefreshMode.KeepCurrentValues, p2);
            DbContext.SubmitChanges();

this way, only chances are updated.</description>
		<content:encoded><![CDATA[<p>Pessoa p2 = new Pessoa();<br />
            p2.Id = 1;<br />
            p2.Nome = &#8220;Teste&#8221; + DateTime.Now.ToString();</p>
<p>            DbContext.Pessoas.Attach(p2);<br />
            DbContext.Refresh(RefreshMode.KeepCurrentValues, p2);<br />
            DbContext.SubmitChanges();</p>
<p>this way, only chances are updated.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-81</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Mon, 17 Mar 2008 22:57:17 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-81</guid>
		<description>I use sprocs for &#039;arbitrary updates&#039;, where I&#039;m updating records I haven&#039;t queried and don&#039;t need to query.

Its not ideal, but its simple, can be called through the linq datacontext, doesn&#039;t require a round trip, doesn&#039;t result in SQL strings in code, and doesn&#039;t require a clumsy hack where you are trying to build the object to update it.</description>
		<content:encoded><![CDATA[<p>I use sprocs for &#8216;arbitrary updates&#8217;, where I&#8217;m updating records I haven&#8217;t queried and don&#8217;t need to query.</p>
<p>Its not ideal, but its simple, can be called through the linq datacontext, doesn&#8217;t require a round trip, doesn&#8217;t result in SQL strings in code, and doesn&#8217;t require a clumsy hack where you are trying to build the object to update it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tomas Jecha</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-80</link>
		<dc:creator>Tomas Jecha</dc:creator>
		<pubDate>Sat, 08 Mar 2008 14:03:33 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-80</guid>
		<description>Nice article, thanks.</description>
		<content:encoded><![CDATA[<p>Nice article, thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DariaK</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-79</link>
		<dc:creator>DariaK</dc:creator>
		<pubDate>Mon, 03 Mar 2008 04:27:30 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-79</guid>
		<description>Here is the tool for database synchronization that supports Linq to Sql object model:

http://perpetuumsoft.com/Product.aspx?lang=en&amp;pid=55

I suppose It is worth to try!</description>
		<content:encoded><![CDATA[<p>Here is the tool for database synchronization that supports Linq to Sql object model:</p>
<p><a href="http://perpetuumsoft.com/Product.aspx?lang=en&#038;pid=55" rel="nofollow">http://perpetuumsoft.com/Product.aspx?lang=en&#038;pid=55</a></p>
<p>I suppose It is worth to try!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam Nofsinger</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-78</link>
		<dc:creator>Adam Nofsinger</dc:creator>
		<pubDate>Mon, 25 Feb 2008 23:15:01 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-78</guid>
		<description>Wow, that really sucks. (The fact that you can&#039;t just do something like:

update c in Customer
where c.CustomerID = 12
set c.Name = &quot;Bob WeHadaBabyItsABoy&quot;</description>
		<content:encoded><![CDATA[<p>Wow, that really sucks. (The fact that you can&#8217;t just do something like:</p>
<p>update c in Customer<br />
where c.CustomerID = 12<br />
set c.Name = &#8220;Bob WeHadaBabyItsABoy&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The LinqDataSource and the Hidden Viewstate - .Net Smoothie</title>
		<link>http://www.richardbushnell.net/2008/02/18/how-to-update-data-with-linq-to-sql/comment-page-1/#comment-77</link>
		<dc:creator>The LinqDataSource and the Hidden Viewstate - .Net Smoothie</dc:creator>
		<pubDate>Thu, 21 Feb 2008 09:01:55 +0000</pubDate>
		<guid isPermaLink="false">http://richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/#comment-77</guid>
		<description>[...] a previous post, I mentioned that LINQ-to-SQL updates can be done in two ways: either you make a call to retrieve a [...]</description>
		<content:encoded><![CDATA[<p>[...] a previous post, I mentioned that LINQ-to-SQL updates can be done in two ways: either you make a call to retrieve a [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

