<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Using DbContext in EF 4.1 Part 12: Automatically Detecting Changes</title><link>http://blogs.msdn.com/b/adonet/archive/2011/02/06/using-dbcontext-in-ef-feature-ctp5-part-12-automatically-detecting-changes.aspx</link><description>&amp;#160; The information in this post is out of date. Visit msdn.com/data/ef for the latest information on current and past releases of EF. For Automatic Detect Changes see http://msdn.com/data/jj556205 &amp;#160; Introduction Version 4.1 of the Entity Framework</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Using DbContext in EF 4.1 Part 12: Automatically Detecting Changes</title><link>http://blogs.msdn.com/b/adonet/archive/2011/02/06/using-dbcontext-in-ef-feature-ctp5-part-12-automatically-detecting-changes.aspx#10360443</link><pubDate>Wed, 17 Oct 2012 16:53:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10360443</guid><dc:creator>Arthur Vickers - MSFT</dc:creator><description>&lt;p&gt;Hi gdoron,&lt;/p&gt;
&lt;p&gt;I think the existing answers on the SO question cover it pretty well. Creating the context is pretty cheap and you&amp;#39;re unlikely to get much benefit from caching in the normal cases. The longer your context lives, the harder it is to work with it in a known and consistent state across requests.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Arthur&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10360443" width="1" height="1"&gt;</description></item><item><title>re: Using DbContext in EF 4.1 Part 12: Automatically Detecting Changes</title><link>http://blogs.msdn.com/b/adonet/archive/2011/02/06/using-dbcontext-in-ef-feature-ctp5-part-12-automatically-detecting-changes.aspx#10359965</link><pubDate>Tue, 16 Oct 2012 11:21:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10359965</guid><dc:creator>gdoron</dc:creator><description>&lt;p&gt;Hi Arthur!&lt;/p&gt;
&lt;p&gt;I know it&amp;#39;s an old post, but can you please answer this question about the recommended pattern for EF Context management?&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://stackoverflow.com/q/12554213/601179"&gt;stackoverflow.com/.../601179&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10359965" width="1" height="1"&gt;</description></item><item><title>re: Using DbContext in EF 4.1 Part 12: Automatically Detecting Changes</title><link>http://blogs.msdn.com/b/adonet/archive/2011/02/06/using-dbcontext-in-ef-feature-ctp5-part-12-automatically-detecting-changes.aspx#10292282</link><pubDate>Tue, 10 Apr 2012 16:25:05 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10292282</guid><dc:creator>Arthur Vickers - MSFT</dc:creator><description>&lt;p&gt;@natalia There is a walkthrough on WinForms data binding with DbContext here: &lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/gg197523(v=vs.103).aspx"&gt;msdn.microsoft.com/.../gg197523(v=vs.103).aspx&lt;/a&gt;. A way to get the child entities deleted is covered in that walkthrough. I&amp;#39;m not sure about the issue with SaveChanges, but if you have worked through the walkthrough and are still having issues I would suggest starting up a thread on Stack Overflow and I (or others) will take a look.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10292282" width="1" height="1"&gt;</description></item><item><title>re: Using DbContext in EF 4.1 Part 12: Automatically Detecting Changes</title><link>http://blogs.msdn.com/b/adonet/archive/2011/02/06/using-dbcontext-in-ef-feature-ctp5-part-12-automatically-detecting-changes.aspx#10292140</link><pubDate>Tue, 10 Apr 2012 08:05:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10292140</guid><dc:creator>natalia</dc:creator><description>&lt;p&gt;Hello Arthur&lt;/p&gt;
&lt;p&gt;I am experiencing a problem with winforms in vs2010. When I introduce a row in a data grid, I have to enter the next row to allow Savechanges to save the just entered row. With as a consequence, that I have a new row in the database (the last one!) with empty values&lt;/p&gt;
&lt;p&gt;Another problem is when deleting a child item in a relationship, it is not deleted phisically from the DB, instead it sets the FK to the parent entity to NULL. I would like to actually delete the child phisically from the db&lt;/p&gt;
&lt;p&gt;I&amp;#39;m not sure how to tackle these two issues, I can imagine I&amp;#39;m not the first one to find these problems but I do not know how to solve them. &lt;/p&gt;
&lt;p&gt;Thanks in advance for any comment on these two issues&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10292140" width="1" height="1"&gt;</description></item><item><title>re: Using DbContext in EF 4.1 Part 12: Automatically Detecting Changes</title><link>http://blogs.msdn.com/b/adonet/archive/2011/02/06/using-dbcontext-in-ef-feature-ctp5-part-12-automatically-detecting-changes.aspx#10250027</link><pubDate>Wed, 21 Dec 2011 16:22:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10250027</guid><dc:creator>Mark Stafford - MSFT</dc:creator><description>&lt;p&gt;Re: performance tips, it really depends on what you&amp;#39;re doing. &amp;nbsp;EF will never be as performant as pure ADO.NET since it makes use of ADO.NET and has its own overhead. &amp;nbsp;That said, there is a wide variety of performance that can be achieved using EF. &amp;nbsp;EFProf and similar tools will give you a good head start as to whehter the problem is in your SQL queries or in your LINQ queries. &amp;nbsp;We are also working on some performance testing right now that we hope to make public within the next few weeks - keep an eye on the blog for the results there. &amp;nbsp;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10250027" width="1" height="1"&gt;</description></item><item><title>re: Using DbContext in EF 4.1 Part 12: Automatically Detecting Changes</title><link>http://blogs.msdn.com/b/adonet/archive/2011/02/06/using-dbcontext-in-ef-feature-ctp5-part-12-automatically-detecting-changes.aspx#10249839</link><pubDate>Wed, 21 Dec 2011 04:49:14 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10249839</guid><dc:creator>No Performance Gain</dc:creator><description>&lt;p&gt;I&amp;#39;m not seeing a performance gain by with: &lt;/p&gt;
&lt;p&gt;Context.Configuration.AutoDetectChangesEnabled = False&lt;/p&gt;
&lt;p&gt;Entity Framework is slower than my old data access layer that used just ADO.NET. &amp;nbsp;I want to use EF, but are there any other tips for performance?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10249839" width="1" height="1"&gt;</description></item><item><title>re: Using DbContext in EF 4.1 Part 12: Automatically Detecting Changes</title><link>http://blogs.msdn.com/b/adonet/archive/2011/02/06/using-dbcontext-in-ef-feature-ctp5-part-12-automatically-detecting-changes.aspx#10157349</link><pubDate>Sat, 23 Apr 2011 12:16:57 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10157349</guid><dc:creator>dotNetDR_</dc:creator><description>&lt;p&gt;thanks dpblogs!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10157349" width="1" height="1"&gt;</description></item><item><title>re: Using DbContext in EF Feature CTP5 Part 12: Automatically Detecting Changes</title><link>http://blogs.msdn.com/b/adonet/archive/2011/02/06/using-dbcontext-in-ef-feature-ctp5-part-12-automatically-detecting-changes.aspx#10137092</link><pubDate>Fri, 04 Mar 2011 20:20:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10137092</guid><dc:creator>Jimmy</dc:creator><description>&lt;p&gt;Hello, thanks for all of your work on this project. I am attempting to use it for a customer and I am stuck. Hopefully you can help.&lt;/p&gt;
&lt;p&gt;I am using DbSet.Add and then SaveChanges on the same record object multiple times. I expected it to realize it is creating the same record multiple times. The code is creating the same principal record twice, then throwing an exception, trying to create the dependent record twice with the same ID as the first principal record.&lt;/p&gt;
&lt;p&gt;Do I need to do a Find() before I Add()?&lt;/p&gt;
&lt;p&gt;[Setup]&lt;/p&gt;
&lt;p&gt;I am using ASP.NET 4, EntityFramework v4.0.30319, &amp;amp; SQL Server 2008 Express. &lt;/p&gt;
&lt;p&gt;I am trying to handle when a user might click &amp;quot;Create new record&amp;quot; multiple times.&lt;/p&gt;
&lt;p&gt;I have two tables in a 1-to-1 relationship, created by CodeFirst.&lt;/p&gt;
&lt;p&gt;I configured the 1-to-1 relationship using information from &lt;a rel="nofollow" target="_new" href="http://weblogs.asp.net/manavi/archive/2010/12/19/entity-association-mapping-with-code-first-one-to-one-shared-primary-key-associations.aspx"&gt;weblogs.asp.net/.../entity-association-mapping-with-code-first-one-to-one-shared-primary-key-associations.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Table #1: Persons. There will always be a person record. It is concise.&lt;/p&gt;
&lt;p&gt;Table #2: Workers. There may be a worker record. The tables are split because the # of worker fields will grow. There will &amp;nbsp;be people who are not workers. I want the Worker.ID to be the same as the Person.ID. I want the Person.ID to be a Primary Key and IDENTITY in SQL server. I want Worker.ID to be a Primary Key, but not an IDENTITY.&lt;/p&gt;
&lt;p&gt;[Domain classes]&lt;/p&gt;
&lt;p&gt; public class Person&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{ &amp;nbsp; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public int ID { get; set; }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public virtual Worker Worker { get; set; }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public class Worker&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public int ID { get; set; }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public virtual Person Person { get; set; }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;...&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;[Associated code #1 -- table builders]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public class PersonBuilder : EntityTypeConfiguration&amp;lt;Person&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public PersonBuilder()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ToTable(&amp;quot;Persons&amp;quot;);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;HasOptional(p =&amp;gt; p.Worker).WithRequired();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public class WorkerBuilder : EntityTypeConfiguration&amp;lt;Worker&amp;gt;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public WorkerBuilder() {}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;[Associated code #2 -- Test initializer]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[TestInitialize]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public void Initialize()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DbDatabase.SetInitializer&amp;lt;MyContext&amp;gt;(new MyInitializer());&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;this.DB = new MyContext();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt;[Failing code: &amp;#39;unit&amp;#39; integration test]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;[TestMethod]&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;public void Worker_test_deduplication()&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;int reccount = 0;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//Arrange&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Records._person2.Worker = Records._worker2;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//Act&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;try&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DB.Persons.Add(Records._person2);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DB.SaveChanges();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DB.Persons.Add(Records._person2);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DB.SaveChanges();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DB.Persons.Add(Records._person2);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DB.SaveChanges();&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;reccount = DB.Persons.Count(n =&amp;gt; n.firstname1 == Records._person2.firstname1);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;catch (Exception e)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Assert.Fail(string.Format(&amp;quot;Unexpected exception of type {0} caught: {1}&amp;quot;,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;e.GetType(), e.Message));&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;//Assert&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Assert.IsTrue(reccount == 1, &amp;quot;Deduplication of records failed.&amp;quot;);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10137092" width="1" height="1"&gt;</description></item><item><title>re: Using DbContext in EF Feature CTP5 Part 12: Automatically Detecting Changes</title><link>http://blogs.msdn.com/b/adonet/archive/2011/02/06/using-dbcontext-in-ef-feature-ctp5-part-12-automatically-detecting-changes.aspx#10131433</link><pubDate>Fri, 18 Feb 2011 15:04:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10131433</guid><dc:creator>Anders</dc:creator><description>&lt;p&gt;Any thoughts on this: &lt;a rel="nofollow" target="_new" href="http://social.msdn.microsoft.com/Forums/en-US/adonetefx/thread/2fb5ceea-9f30-4665-af98-945c6485f60b"&gt;social.msdn.microsoft.com/.../2fb5ceea-9f30-4665-af98-945c6485f60b&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10131433" width="1" height="1"&gt;</description></item><item><title>re: Using DbContext in EF Feature CTP5 Part 12: Automatically Detecting Changes</title><link>http://blogs.msdn.com/b/adonet/archive/2011/02/06/using-dbcontext-in-ef-feature-ctp5-part-12-automatically-detecting-changes.aspx#10131087</link><pubDate>Thu, 17 Feb 2011 19:54:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10131087</guid><dc:creator>Arthur</dc:creator><description>&lt;p&gt;@Ashraf The plan is to relase Code First/DbContext with a Go-Live license in the first quarter of this year.&lt;/p&gt;
&lt;p&gt;@Andrey Thanks for the suggestion.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10131087" width="1" height="1"&gt;</description></item></channel></rss>