<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.microsoft.co.il/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>Bnaya Eshet : Entity Framework</title><link>http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Entity+Framework/default.aspx</link><description>Tags: Entity Framework</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>EF should adopt the WAQS framework</title><link>http://blogs.microsoft.co.il/blogs/bnaya/archive/2013/05/07/ef-should-adopt-the-waqs-framework.aspx</link><pubDate>Tue, 07 May 2013 09:08:33 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:2004352</guid><dc:creator>bnaya</dc:creator><slash:comments>0</slash:comments><description>&lt;h2&gt;EF should adopt the &lt;strong&gt;WAQS&lt;/strong&gt; framework&lt;/h2&gt;  &lt;p&gt;I was speaking with &lt;a href="http://msmvps.com/blogs/matthieu/default.aspx"&gt;Matthieu MEZIL&lt;/a&gt; about his &lt;a href="http://www.dailymotion.com/video/xuc1jb_waqs-application-scaffolding_tech"&gt;WAQS&lt;/a&gt;&lt;strong&gt;&lt;/strong&gt; framework,     &lt;br /&gt;it is a layer of abstraction over the &lt;strong&gt;Entity Framework&lt;/strong&gt; which I think you should check out.     &lt;br /&gt;&lt;strong&gt;Matthieu&lt;/strong&gt; is working on it on his free time (currently as an open source) and it is amazing to see what he was able to achieve.     &lt;br /&gt;this framework is already been in used by some of &lt;strong&gt;real word company&lt;/strong&gt; and it is improving over time (today Matthieu is working on a new version of it).&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/bnaya/IMG_6590_7676_317C194F.jpg"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="WAQS, EF, Database, ORM" border="0" alt="WAQS, EF, Database, ORM" src="http://blogs.microsoft.co.il/blogs/bnaya/IMG_6590_7676_thumb_1B81BF8B.jpg" width="533" height="429" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;as I see it, Microsoft EF team should adopt this framework as part of the EF open source project. &lt;strong&gt;I hope that the EF team will put the effort to merge it into their source code&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;WAQS is addressing many of the painful scenarios under EF, with a great design and&amp;#160; productivity. &lt;/p&gt;  &lt;p&gt;as I understand &lt;strong&gt;Matthieu is willing to let the EF team to take ownership&lt;/strong&gt; over his labor and I believe that it is an opportunity that will be pity to waste (everything within this framework came out of Matthieu&amp;#39;s field experience in order to ease his customer pain).&lt;/p&gt;  &lt;p&gt;this post is a call to action, if you like this framework or the ideas it represent &lt;strong&gt;&lt;font size="2"&gt;vote&lt;/font&gt; for it at&lt;/strong&gt;:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://data.uservoice.com/forums/72025-entity-framework-feature-suggestions/suggestions/3929780-waqs" href="http://data.uservoice.com/forums/72025-entity-framework-feature-suggestions/suggestions/3929780-waqs"&gt;http://data.uservoice.com/forums/72025-entity-framework-feature-suggestions/suggestions/3929780-waqs&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=2004352" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/SELA/default.aspx">SELA</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/EF/default.aspx">EF</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/ORM/default.aspx">ORM</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/SDP/default.aspx">SDP</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Database/default.aspx">Database</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/WAQS/default.aspx">WAQS</category></item><item><title>EF 6: Async</title><link>http://blogs.microsoft.co.il/blogs/bnaya/archive/2013/03/19/ef-6-async.aspx</link><pubDate>Tue, 19 Mar 2013 15:02:51 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1811777</guid><dc:creator>bnaya</dc:creator><slash:comments>0</slash:comments><description>&lt;h2&gt;EF 6: Async&lt;/h2&gt;  &lt;p&gt;this post is the first in a series about what&amp;#39;s new in &lt;strong&gt;EF 6&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;great improvements are about to come with &lt;strong&gt;Entity Framework 6&lt;/strong&gt;.     &lt;br /&gt;it is a major release and the first one since EF become an open source.     &lt;br /&gt;each post in the series will be dedicate to a single feature.&lt;/p&gt;  &lt;p&gt;this post will focus on a new&lt;strong&gt; EF a-sync&lt;/strong&gt; features.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/bnaya/IMG_1416_38605C8C.jpg"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="EF, Parallel, async, await, task, api, entity" border="0" alt="EF, Parallel, async, await, task, api, entity" src="http://blogs.microsoft.co.il/blogs/bnaya/IMG_1416_thumb_7DE49B10.jpg" width="508" height="351" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;the first question that should be asked is, why do we need &lt;strong&gt;parallel data access&lt;/strong&gt;?     &lt;br /&gt;moreover why do we need a &lt;strong&gt;dedicate parallel data access API&lt;/strong&gt;, rather then using the TPL Task.Run(…) in order to introduce parallelism?&lt;/p&gt;  &lt;p&gt;the answer is related both to &lt;strong&gt;thread safety &lt;/strong&gt;and &lt;strong&gt;ThreadPool&lt;/strong&gt; &lt;strong&gt;optimization&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;a &lt;strong&gt;dedicate data access API&lt;/strong&gt; for &lt;strong&gt;parallel&lt;/strong&gt; programming, ensured a &lt;strong&gt;thread safe access&lt;/strong&gt;, which may not be a trivial task.&lt;/p&gt;  &lt;p&gt;furthermore, when the database is executing a query the .NET thread is idle (waiting for the execution result).    &lt;br /&gt;if this idle thread has taken from &lt;strong&gt;ThreadPool&lt;/strong&gt; (either directly or through high level API like TPL Task.Run(…)) it could lead to a ThreadPool &lt;strong&gt;starvation&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;assuming that you have a 2 second query, Task.Run(…) will hold the ThreadPool&amp;#39;s thread for 2 second even though it idle while the database is executing the query.&lt;/p&gt;  &lt;p&gt;what you really want is an &lt;strong&gt;API that operate over IOCP&lt;/strong&gt; (IO completion port). &lt;strong&gt;IOCP&lt;/strong&gt; &lt;strong&gt;API&lt;/strong&gt; will release the ThreadPool&amp;#39;s thread back to the pool and &lt;strong&gt;re-claim&lt;/strong&gt; &lt;strong&gt;a thread&lt;/strong&gt; at the completion time.&lt;/p&gt;  &lt;p&gt;at the API level you can find &lt;strong&gt;a-sync operations everywhere&lt;/strong&gt;.     &lt;br /&gt;I will present some of the main API.&lt;/p&gt;  &lt;p&gt;the following snippets, will use the following &lt;strong&gt;entities&lt;/strong&gt; (code first):&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:fbe34654-313a-4d52-8dce-d057a79ee95b" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;Code Snippet&lt;/div&gt; &lt;div style="background:#fff;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Author&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; Author()&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;Blogs = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;List&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Blog&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;gt;();&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; Id { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; Name { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;IList&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Blog&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;gt; Blogs { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&amp;nbsp;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Blog&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; Id { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; Title { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;string&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; Content { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; AuthorId { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&amp;nbsp;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;and the following &lt;strong&gt;context&lt;/strong&gt;:&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:28fbb720-798b-4adc-b525-a499891febb1" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;Code Snippet&lt;/div&gt; &lt;div style="background:#fff;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;class&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Context&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; : &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;DbContext&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;DbSet&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Author&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;gt; Authors { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;public&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;DbSet&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;lt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Blog&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&amp;gt; Blogs { &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;get&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;set&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;; }&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;h5&gt;a-sync save&lt;/h5&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:83e348f2-9cd6-4ca0-9de9-860ef135b5f8" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;Code Snippet&lt;/div&gt; &lt;div style="background:#ddd;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; (&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; context = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Context&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;())&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;context.Authors.Add(author);&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; affected = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;await&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; context.SaveChangesAsync();&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;notice the &lt;a href="http://blogs.microsoft.co.il/blogs/bnaya/archive/2011/12/29/the-concept-of-async-await.aspx"&gt;await&lt;/a&gt; at line 4.&lt;/p&gt;  &lt;h5&gt;a-sync read&lt;/h5&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1f2f32d3-f7d9-42c6-99d2-f65460397626" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;Code Snippet&lt;/div&gt; &lt;div style="background:#ddd;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; (&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; context = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Context&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;())&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Author&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;[] authors = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;await&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; context.Authors&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;.Include(a =&amp;gt; a.Blogs)&lt;/span&gt;&lt;/li&gt; &lt;li&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;.ToArrayAsync();&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;return&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; authors;&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&lt;strong&gt;line 5&lt;/strong&gt;, is where the magic happens.&lt;/p&gt;  &lt;h5&gt;execute command&lt;/h5&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:115f7c17-c8a6-4787-9ef2-d31583d09f3f" class="wlWriterEditableSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;Code Snippet&lt;/div&gt; &lt;div style="background:#fff;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;using&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; (&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;var&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; context = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;new&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;span style="background:#ffffff;color:#2b91af;"&gt;Context&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;())&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;{&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    &lt;span style="background:#ffffff;color:#000000;"&gt;&lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;int&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; affected = &lt;/span&gt;&lt;span style="background:#ffffff;color:#0000ff;"&gt;await&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt; &lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="background:#ffffff;color:#000000;"&gt;context.Database.ExecuteSqlCommandAsync(&lt;/span&gt;&lt;span style="background:#ffffff;color:#a31515;"&gt;&amp;quot;DELETE FROM BLOGS&amp;quot;&lt;/span&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;);&lt;/span&gt;&lt;/li&gt; &lt;li&gt;&lt;span style="background:#ffffff;color:#000000;"&gt;}&lt;/span&gt;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;h5&gt;summary&lt;/h5&gt;  &lt;p&gt;&lt;strong&gt;EF 6&lt;/strong&gt; is having a great parallel API, which respect &lt;strong&gt;IOCP&lt;/strong&gt; and compatible with the new &lt;strong&gt;async / await&lt;/strong&gt; syntax. &lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.seladeveloperpractice.com/"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="EF, Parallel, async, await, task, api, entity, sdp" border="0" alt="EF, Parallel, async, await, task, api, entity,sdp" src="http://blogs.microsoft.co.il/blogs/bnaya/sdp-2013_7B87C6BA.png" width="316" height="125" /&gt;&lt;/a&gt;     &lt;br /&gt;&lt;/p&gt; &lt;a href="http://dotnetshoutout.com/EF-6-Async-Bnaya-Eshet"&gt;&lt;img style="border-right-width:0px;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fblogs.microsoft.co.il%2Fblogs%2Fbnaya%2Farchive%2F2013%2F03%2F19%2Fef-6-async.aspx" /&gt;&lt;/a&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1811777" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/SELA/default.aspx">SELA</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Parallel/default.aspx">Parallel</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/EF/default.aspx">EF</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Task/default.aspx">Task</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Thread/default.aspx">Thread</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/async/default.aspx">async</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/await/default.aspx">await</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/TAP/default.aspx">TAP</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/api/default.aspx">api</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/entity/default.aspx">entity</category></item><item><title>Entity Framework - Pro and Con</title><link>http://blogs.microsoft.co.il/blogs/bnaya/archive/2013/01/13/entity-framework-pro-and-con.aspx</link><pubDate>Sun, 13 Jan 2013 12:49:03 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:1658210</guid><dc:creator>bnaya</dc:creator><slash:comments>0</slash:comments><description>&lt;h2&gt;Entity Framework - Pro and Con&lt;/h2&gt;  &lt;p&gt;Consulting as part of a consultant group can lead to better consulting.    &lt;br /&gt;Sela Israel consultant group is around 40 consultants many of them are speakers in local and international conference.&lt;/p&gt;  &lt;p&gt;It happens that one of our customers was having some issues around the usage of Entity Framework.    &lt;br /&gt;even those I was thinking that I&amp;#39;m having most of the answer for that customer I decided to use our internal channel to query what are my colleagues opinions about those issues and sea whether they can enlighten a broader spectrum.&lt;/p&gt;  &lt;p&gt;finally we end up with a very broad comprehended which we believe can be beneficial for a broader audience. it was Sasha advice that we should put a summary of our internal conversation into a blog post.&lt;/p&gt;  &lt;p&gt;I will start with a few words about our customer&amp;#39;s business.    &lt;br /&gt;the customer is using Entity Framework in a distributed environments.&lt;/p&gt;  &lt;p&gt;his question was divided into a general ones and more focus, I will introduce each question and a summary of different answers provided by my colleagues and me.&lt;/p&gt;  &lt;p&gt;I may say that many answers can be also true for other ORM frameworks like NHibernate.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/bnaya/Untitled_HDR2_022F42AE.jpg"&gt;&lt;img style="background-image:none;border-right-width:0px;padding-left:0px;padding-right:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" title="EF, ADO, Pro, Con, leak, context" border="0" alt="EF, ADO, Pro, Con, leak, context" src="http://blogs.microsoft.co.il/blogs/bnaya/Untitled_HDR2_thumb_34466D2B.jpg" width="521" height="362" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;h3&gt;the questions:&lt;/h3&gt;  &lt;h4&gt;High-Level:&lt;/h4&gt;  &lt;h5&gt;What are the best justifications for changing an existing system to work with entity framework?&lt;/h5&gt;  &lt;ul&gt;   &lt;li&gt;All-in-1 framework for mapping tables to classes, no need to write mapping code which is hard to maintain. &lt;/li&gt;    &lt;li&gt;Maintainability, easy to understand code, no need for plumbing or creating big data access layers. &lt;/li&gt;    &lt;li&gt;Provides LINQ queries over databases, which requires less understanding of SQL from junior developers. &lt;/li&gt;    &lt;li&gt;EF can be used as the base for data services and OData. &lt;/li&gt; &lt;/ul&gt;  &lt;h5&gt;What are the scenarios you would defiantly NOT recommend to use entity framework?&lt;/h5&gt;  &lt;ul&gt;   &lt;li&gt;real-time apps. &lt;/li&gt;    &lt;li&gt;Code can only access the database through stored procedures. EF advantage is LINQ and change tracking which is not used when working solely with SPs (even those EF does have limited support for SP). &lt;/li&gt;    &lt;li&gt;Frequently insert operations (inserts). Bulk is not supported yet by EF. &lt;/li&gt;    &lt;li&gt;Frequently update operation, mainly when the update is targeting multiple rows (with a single value)      &lt;br /&gt;for example: UPDATE TableName SET ColumA = 10 WHERE ColumnB = ?       &lt;br /&gt;this kind of update does better be used with ExecuteNonQuery (either from the context or directly from Ado.Net). &lt;/li&gt;    &lt;li&gt;De-normalized tables and high performance queries. EF generates queries and they are hard to manipulate, and it doesn&amp;#39;t map well to de-normalized tables. &lt;/li&gt; &lt;/ul&gt;  &lt;h5&gt;We want to work in a method of loading ALL data into memory is that recommended using Entity framework? What problems should we expect?&lt;/h5&gt;  &lt;ul&gt;   &lt;li&gt;Loading all entities will require many queries and a lot of time. &lt;/li&gt;    &lt;li&gt;Memory overhead. &lt;/li&gt;    &lt;li&gt;Latencies because of the EF change tracking and large collection handling. &lt;/li&gt;    &lt;li&gt;EF contexts are not thread-safe, you should not use one context for the entire service. &lt;/li&gt;    &lt;li&gt;If you do intend to do that, use EF for loading entities, but not for managing them (detach the entities from the content). &lt;/li&gt;    &lt;li&gt;do not use the context as a cache object (for distributed scenarios)      &lt;br /&gt;it is not thread safe, having overheads and doesn&amp;#39;t follow the idea of separation of concern. it is much better to use a designated cache API like AppFabric Cache. &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Technical-Level:&lt;/h4&gt;  &lt;h5&gt;Memory leaks:&lt;/h5&gt;  &lt;p&gt;We have a scenario where every 10 seconds we open a context to get a single table and close it. &amp;quot;using (entities context = new entities(_connection)) {… }&amp;quot;    &lt;br /&gt;this caused a memory leak over a period of a few hours.&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;I suggest you check the origin of the memory leaks to make sure it&amp;#39;s from EF. EF is an open source now, so any memory leak can be reported and fixed. &lt;/li&gt;    &lt;li&gt;Use the Profiler and VMMap in order of tracing the leak&amp;#39;s root. &lt;/li&gt; &lt;/ul&gt;  &lt;h5&gt;Should we keep the context open in this case?&lt;/h5&gt;  &lt;ul&gt;   &lt;li&gt;It doesn&amp;#39;t really matter, as the query will execute either way. However, it&amp;#39;s preferable to close contexts so the cached entities will be GC&amp;#39;d, otherwise the context and the cached entities will be upgraded to Gen2 and will get stuck there for the duration of the service. &lt;/li&gt;    &lt;li&gt;NO! Use context per request for WCF. &lt;/li&gt;    &lt;li&gt;The recommended practice is to open a context per action because once an item is added to the DB your context Is outdated and might cause data corruption or duplicated items &lt;/li&gt; &lt;/ul&gt;  &lt;h5&gt;Does the size of the Edmx effects this?&lt;/h5&gt;  &lt;ul&gt;   &lt;li&gt;The size of Edmx affects the first creation of the context since all the Edmx data is loaded into memory. &lt;/li&gt;    &lt;li&gt;The EDMX is loaded into the memory, parsed, and the mapping is created and cached in the AppDomain. You can close and reopen contexts without it affecting the cached Edmx mappings. &lt;/li&gt; &lt;/ul&gt;  &lt;h5&gt;Working with large number of tables&lt;/h5&gt;  &lt;h5&gt;Should all the tables be put in a single Edmx or split between several Edmx files?    &lt;br /&gt;How one can manage an edmx with large number of entities? for example, how one can find?&lt;/h5&gt;  &lt;p&gt;and modify a specific table in the designer?&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;If you split between Edmx files, you cannot connect entities one to the other (navigation properties).      &lt;br /&gt;You should build your model according to your entity model design – if you have groups of entities which are independent they can be in separate Edmx models.       &lt;br /&gt;EDMX files are known to handle a couple of hundreds of entity types. If the number of entity types is over 1000, I would consider splitting to several Edmxs (and rethink your entity model design, because thousands of entity types seems too much for one system). &lt;/li&gt;    &lt;li&gt;Move to VS 2012 in order to have designer enhancements like split and coloring, see the following &lt;a href="http://msdn.microsoft.com/en-us/data/jj519700.aspx" target="_blank"&gt;link&lt;/a&gt;. &lt;/li&gt;    &lt;li&gt;The EF designer has several improvements, such as coloring entities to differentiate entities groups.      &lt;br /&gt;There are also 3-rd party entity designers that might give better UX.       &lt;br /&gt;And remember – EF is an open source, you can send them requests and even contribute your own additions to it, so search in EDMX designer sounds interesting. &lt;/li&gt;    &lt;li&gt;you should split the Edmx to couple of Edmx files per domain/service. &lt;/li&gt; &lt;/ul&gt;  &lt;h5&gt;Relationships between tables&lt;/h5&gt;  &lt;h5&gt;Working in lazy vs. not lazy mode?&lt;/h5&gt;  &lt;ul&gt;   &lt;li&gt;In general Lazy code is evil for distributed scenarios. &lt;/li&gt;    &lt;li&gt;If they need data from couple of tables then use Include else you can use lazy loading. &lt;/li&gt; &lt;/ul&gt;  &lt;h5&gt;Does the &amp;quot;Include&amp;quot; command load the entire table or only the records related&amp;#160; to the original ObjectSet?&lt;/h5&gt;  &lt;ul&gt;   &lt;li&gt;Include loads the columns of the related entity. EF doesn&amp;#39;t use * in queries. &lt;/li&gt; &lt;/ul&gt;  &lt;h5&gt;How can we perform bulk insert/update using EF? &lt;/h5&gt;  &lt;ul&gt;   &lt;li&gt;You cannot do it with EF entities, you need to use raw SQL. &lt;/li&gt; &lt;/ul&gt;  &lt;h5&gt;When an entity is marked as modified, EF updates all the columns?&lt;/h5&gt;  &lt;ul&gt;   &lt;li&gt;It doesn&amp;#39;t update all the columns, unless you are using distributed apps with self-tracking. The &amp;quot;normal&amp;quot; implementation of EF only updates modified columns. With self-tracking the mechanism does not keep track of which property was updated, so it marks all properties as updated. You can edit the self-tracking code and fix it if it&amp;#39;s required. &lt;/li&gt;    &lt;li&gt;You can attach SP in order to have a custom logic. &lt;/li&gt;    &lt;li&gt;You can change the T4 file in order to maintain all original values in self-tracking scenario. &lt;/li&gt; &lt;/ul&gt;  &lt;h5&gt;What&amp;#39;s the overhead of entire raw updating?&lt;/h5&gt;  &lt;ul&gt;   &lt;li&gt;Mostly DB overhead to recalculate indexes I presume. This is more a question to a DBA. &lt;/li&gt; &lt;/ul&gt;  &lt;h5&gt;When we used EF to update an XML column with XML file which is 700-800KB, We received an exception related to Sql Server&amp;#39;s TempDb. what can cause it?&lt;/h5&gt;  &lt;ul&gt;   &lt;li&gt;Probably relates to how the database works with temporary tables for updating XML content.      &lt;br /&gt;You should have your database checked out by a DBA, perhaps you need to increase the size of your TempDb. &lt;/li&gt;    &lt;li&gt;In general large object like those Xml will make a memory pressure on the GC&amp;#39;s Large Object Heap, you should consider to move to .NET 4.5 where the GC does defragment the Large Object Heap. &lt;/li&gt;    &lt;li&gt;You can consider to store the XML as byte[] which can be compressed (Xml is not a very economic format). &lt;/li&gt; &lt;/ul&gt;  &lt;h5&gt;What&amp;#39;s the overhead of using EF vs. ADO.Net?&lt;/h5&gt;  &lt;ul&gt;   &lt;li&gt;The overhead of taking a data reader an transforming the results to objects, and the overhead of compiling SQL queries from LINQ.      &lt;br /&gt;You will have the same overhead and even more, if you try to build your own ORM framework. Don’t do that! &lt;/li&gt;    &lt;li&gt;When you have abstraction layer you get overhead. The overhead depends on what they do with EF. &lt;/li&gt;    &lt;li&gt;in general you should conceder to get away from Inheritance because it does have a greater overhead. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h5&gt;Credits:&lt;/h5&gt;  &lt;p&gt;I want to credits the main contribution for this conversation which was &lt;a href="http://blogs.microsoft.co.il/blogs/idof/" target="_blank"&gt;Ido Flatow&lt;/a&gt;, &lt;a href="http://blogs.microsoft.co.il/blogs/gilf/" target="_blank"&gt;Gil Fink&lt;/a&gt;, &lt;a href="http://blogs.microsoft.co.il/blogs/roadan/" target="_blank"&gt;Yaniv Rodenski&lt;/a&gt;, &lt;a href="http://www.linkedin.com/in/razamit" target="_blank"&gt;Amit Raz&lt;/a&gt;, &lt;a href="http://www.linkedin.com/pub/ofir-makmal/4/626/800" target="_blank"&gt;Ofir Makmal&lt;/a&gt;, &lt;a href="http://www.linkedin.com/pub/tomer-shaiman/19/293/142" target="_blank"&gt;Tomer Shaiman&lt;/a&gt; and I&amp;#39;m hopping that I didn&amp;#39;t miss anyone.&lt;/p&gt;  &lt;br /&gt;&lt;a href="http://dotnetshoutout.com/Entity-Framework-Pro-and-Con-Bnaya-Eshet"&gt;&lt;img style="border-right-width:0px;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fblogs.microsoft.co.il%2Fblogs%2Fbnaya%2Farchive%2F2013%2F01%2F13%2Fentity-framework-pro-and-con.aspx" /&gt;&lt;/a&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=1658210" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/SELA/default.aspx">SELA</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/EF/default.aspx">EF</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/BulkInsert/default.aspx">BulkInsert</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Memory+leak/default.aspx">Memory leak</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/ADO/default.aspx">ADO</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Con/default.aspx">Con</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/leak/default.aspx">leak</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/context/default.aspx">context</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Pro/default.aspx">Pro</category></item><item><title>The hidden assumption of EF 4 self-tracking entity</title><link>http://blogs.microsoft.co.il/blogs/bnaya/archive/2010/10/20/the-hidden-assumption-of-ef-4-self-tracking-entity.aspx</link><pubDate>Thu, 21 Oct 2010 03:04:24 GMT</pubDate><guid isPermaLink="false">b5c4f5bc-c09b-4439-a595-91a98c1847df:728677</guid><dc:creator>bnaya</dc:creator><slash:comments>0</slash:comments><description>&lt;h2&gt;The hidden assumption of EF 4 self-tracking entity&lt;/h2&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/bnaya/1287555061_database1_7E4F86F4.jpg"&gt;&lt;img style="border-right-width:0px;margin:0px 10px 0px 0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="EF, Entity Framework, Self tracking" border="0" alt="EF, Entity Framework, Self tracking" align="left" src="http://blogs.microsoft.co.il/blogs/bnaya/1287555061_database1_thumb_1EC6A0DA.jpg" width="125" height="125" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;recently I was diving into the &lt;strong&gt;Entity Framework self-tracking&lt;/strong&gt; &lt;strong&gt;entity&lt;/strong&gt; &lt;strong&gt;T4&lt;/strong&gt; and its generated code.&lt;/p&gt;  &lt;p&gt;doing so I was finding some interesting assumptions made about the entity behaviors.&lt;/p&gt;  &lt;p&gt;this post will illuminate some of those assumptions.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h5&gt;Background&lt;/h5&gt;  &lt;p&gt;&lt;strong&gt;EF self tracking entity&lt;/strong&gt; is one of the major enhancement of &lt;strong&gt;EF 4.0&lt;/strong&gt;,&lt;/p&gt;  &lt;p&gt;it is a disconnected model (&lt;font color="#808080"&gt;&lt;em&gt;similar to the old DataSet&lt;/em&gt;&lt;/font&gt;) which enable tracking &lt;/p&gt;  &lt;p&gt;the entity state (&lt;em&gt;&lt;font color="#808080"&gt;Added, Modified, Deleted and Unchanged&lt;/font&gt;&lt;/em&gt;) while the entity&lt;/p&gt;  &lt;p&gt;is detached from the &lt;strong&gt;EF&lt;/strong&gt;&lt;strong&gt; ObjectContext&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;the code snippet of this post will refer the following very simple edmx:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.microsoft.co.il/blogs/bnaya/image_7C8E9553.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="EF, Entity Framework, Self tracking" border="0" alt="EF, Entity Framework, Self tracking" src="http://blogs.microsoft.co.il/blogs/bnaya/image_thumb_7A71968A.png" width="164" height="154" /&gt;&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;h5&gt;Assumptions&lt;/h5&gt;  &lt;h6&gt;&lt;font color="#0000ff"&gt;1st assumption&lt;/font&gt;&lt;/h6&gt;  &lt;p&gt;by default the tracking is disable (&lt;strong&gt;ChangeTrackingEnabled = false&lt;/strong&gt;).&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h6&gt;&lt;font color="#0000ff"&gt;2nd assumption&lt;/font&gt;&lt;/h6&gt;  &lt;p&gt;trying to change the entity state while the tracking is disable&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9d65f345-6607-479b-bea6-6d79ed1f4e2a" class="wlWriterSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;Code Snippet&lt;/div&gt; &lt;div style="background:#ddd;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff;"&gt;var&lt;/span&gt; p = &lt;span style="color:#0000ff;"&gt;new&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;Person&lt;/span&gt;();&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;p.ChangeTracker.State = &lt;span style="color:#2b91af;"&gt;ObjectState&lt;/span&gt;.Unchanged;&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;will have &lt;strong&gt;no affect&lt;/strong&gt; on the entity state (&lt;em&gt;&lt;font color="#808080"&gt;the state will remain Added which is the default &lt;/font&gt;&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;&lt;em&gt;&lt;font color="#808080"&gt;state for new entities&lt;/font&gt;&lt;/em&gt;).&lt;/p&gt;  &lt;p&gt;&lt;em&gt;the following snippet shows the code of the &lt;strong&gt;State&lt;/strong&gt; property:&lt;/em&gt;&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:c5a5dc46-7e9d-4833-9001-5e673fd801c6" class="wlWriterSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;T4 generated code&lt;/div&gt; &lt;div style="background:#ddd;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;ObjectState&lt;/span&gt; State&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff;"&gt;get&lt;/span&gt; { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _objectState; }&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="color:#0000ff;"&gt;set&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (_isDeserializing || _changeTrackingEnabled)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            OnObjectStateChanging(&lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;            _objectState = &lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        }&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;h6&gt;&amp;#160;&lt;/h6&gt;  &lt;h6&gt;&lt;font color="#0000ff"&gt;3rd assumption&lt;/font&gt;&lt;/h6&gt;  &lt;p&gt;the entity enable the tracking after deserialization.&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:78a41d3c-c953-4b28-9172-69156dbbe980" class="wlWriterSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;T4 generated code&lt;/div&gt; &lt;div style="background:#ddd;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;"&gt; &lt;li&gt;[&lt;span style="color:#2b91af;"&gt;OnDeserialized&lt;/span&gt;]&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; OnDeserializedMethod(&lt;span style="color:#2b91af;"&gt;StreamingContext&lt;/span&gt; context)&lt;/li&gt; &lt;li&gt;{&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    IsDeserializing = &lt;span style="color:#0000ff;"&gt;false&lt;/span&gt;;&lt;/li&gt; &lt;li&gt;    ChangeTracker.ChangeTrackingEnabled = &lt;span style="color:#0000ff;"&gt;true&lt;/span&gt;;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h6&gt;&lt;font color="#0000ff"&gt;4th assumption&lt;/font&gt;&lt;/h6&gt;  &lt;p&gt;MarkAsAdded, MarkAsModified, MarkAsDeleted and MarkAsUnchanged all &lt;strong&gt;enable the trucking&lt;/strong&gt;.&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:61c390ca-432e-41e8-b5e7-f9552307d704" class="wlWriterSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;T4 generated code&lt;/div&gt; &lt;div style="background:#ddd;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; T MarkAsAdded&amp;lt;T&amp;gt;(&lt;span style="color:#0000ff;"&gt;this&lt;/span&gt; T trackingItem) &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt; T : &lt;span style="color:#2b91af;"&gt;IObjectWithChangeTracker&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;{    &lt;/li&gt; &lt;li&gt;    trackingItem.ChangeTracker.ChangeTrackingEnabled = &lt;span style="color:#0000ff;"&gt;true&lt;/span&gt;;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    trackingItem.ChangeTracker.State = &lt;span style="color:#2b91af;"&gt;ObjectState&lt;/span&gt;.Added;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; trackingItem;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h6&gt;&lt;font color="#0000ff"&gt;5th assumption&lt;/font&gt;&lt;/h6&gt;  &lt;p&gt;State = ObjectState.Unchanged, MarkAsUnchanged and AcceptChanges &lt;/p&gt;  &lt;p&gt;has different behaviors:&lt;/p&gt;  &lt;p&gt;in general &lt;strong&gt;State property:&lt;/strong&gt; is only changing when tracking is enabled,&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;MarckAsUnchanged:&lt;/strong&gt; enable the tracking and&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;AcceptChanges:&lt;/strong&gt; clear the original values, enable the tracking and &lt;/p&gt;  &lt;p&gt;reset the relationship tracking (&lt;em&gt;&lt;font color="#808080"&gt;added and removed related entities&lt;/font&gt;&lt;/em&gt;).&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:ce0b475d-d9ec-424f-89de-5b353c672fc2" class="wlWriterSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;State: T4 generated code&lt;/div&gt; &lt;div style="background:#ddd;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2.5em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#2b91af;"&gt;ObjectState&lt;/span&gt; State&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;{&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff;"&gt;get&lt;/span&gt; { &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; _objectState; }&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    &lt;span style="color:#0000ff;"&gt;set&lt;/span&gt;&lt;/li&gt; &lt;li&gt;    {&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        &lt;span style="color:#0000ff;"&gt;if&lt;/span&gt; (_isDeserializing || _changeTrackingEnabled)&lt;/li&gt; &lt;li&gt;        {&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;            OnObjectStateChanging(&lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;);&lt;/li&gt; &lt;li&gt;            _objectState = &lt;span style="color:#0000ff;"&gt;value&lt;/span&gt;;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;        }&lt;/li&gt; &lt;li&gt;    }&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:f8cbb5ab-3725-4f92-9ffa-e3e72ac5c854" class="wlWriterSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;MarkAsUnchanged: T4&lt;/div&gt; &lt;div style="background:#ddd;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;static&lt;/span&gt; T MarkAsUnchanged&amp;lt;T&amp;gt;(&lt;span style="color:#0000ff;"&gt;this&lt;/span&gt; T trackingItem) &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt; T : &lt;span style="color:#2b91af;"&gt;IObjectWithChangeTracker&lt;/span&gt;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;{    &lt;/li&gt; &lt;li&gt;    trackingItem.ChangeTracker.ChangeTrackingEnabled = &lt;span style="color:#0000ff;"&gt;true&lt;/span&gt;;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    trackingItem.ChangeTracker.State = &lt;span style="color:#2b91af;"&gt;ObjectState&lt;/span&gt;.Unchanged;&lt;/li&gt; &lt;li&gt;    &lt;span style="color:#0000ff;"&gt;return&lt;/span&gt; trackingItem;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:419d06b7-0045-4359-92f5-f426858c4ebb" class="wlWriterSmartContent"&gt; &lt;div style="border:#000080 1px solid;color:#000;font-family:&amp;#39;Courier New&amp;#39;, Courier, Monospace;font-size:10pt;"&gt; &lt;div style="background:#000080;color:#fff;font-family:Verdana, Tahoma, Arial, sans-serif;font-weight:bold;padding:2px 5px;"&gt;AcceptChang: T4 generated code&lt;/div&gt; &lt;div style="background:#ddd;overflow:auto;"&gt; &lt;ol style="background:#ffffff;margin:0 0 0 2em;padding:0 0 0 5px;"&gt; &lt;li&gt;&lt;span style="color:#0000ff;"&gt;public&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;void&lt;/span&gt; AcceptChanges()&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;{&lt;/li&gt; &lt;li&gt;    OnObjectStateChanging(&lt;span style="color:#2b91af;"&gt;ObjectState&lt;/span&gt;.Unchanged);&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    OriginalValues.Clear();&lt;/li&gt; &lt;li&gt;    ObjectsAddedToCollectionProperties.Clear();&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    ObjectsRemovedFromCollectionProperties.Clear();&lt;/li&gt; &lt;li&gt;    ChangeTrackingEnabled = &lt;span style="color:#0000ff;"&gt;true&lt;/span&gt;;&lt;/li&gt; &lt;li style="background:#f3f3f3;"&gt;    _objectState = &lt;span style="color:#2b91af;"&gt;ObjectState&lt;/span&gt;.Unchanged;&lt;/li&gt; &lt;li&gt;}&lt;/li&gt; &lt;/ol&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;h5&gt;Summary&lt;/h5&gt;  &lt;p&gt;the &lt;strong&gt;self tracking entity&lt;/strong&gt; is a fairly young concept in the &lt;strong&gt;EF&lt;/strong&gt; world &lt;/p&gt;  &lt;p&gt;and we can expect that it will keep changing. &lt;/p&gt;  &lt;p&gt;as I was reading in one of the Harry Potter&amp;#39;s book&lt;/p&gt;  &lt;p&gt;&amp;quot;do not trust anything you cannot understand&amp;quot;, so be aware of that&lt;/p&gt;  &lt;p&gt;assumption and use it well.&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;a href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fblogs.microsoft.co.il%2fblogs%2fbnaya%2farchive%2f2010%2f10%2f20%2fthe-hidden-assumption-of-ef-4-self-tracking-entity.aspx"&gt;&lt;img border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt; &lt;a href="http://dotnetshoutout.com/The-hidden-assumption-of-EF-4-self-tracking-entity-Export-Bnaya-Eshet"&gt;&lt;img style="border-right-width:0px;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" alt="Shout it" src="http://dotnetshoutout.com/image.axd?url=http%3A%2F%2Fblogs.microsoft.co.il%2Fblogs%2Fbnaya%2Farchive%2F2010%2F10%2F20%2Fthe-hidden-assumption-of-ef-4-self-tracking-entity.aspx" /&gt;&lt;/a&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:right;margin:0px;padding:4px 0px 4px 0px;"&gt;&lt;a href="http://digg.com/submit?url=http%3a%2f%2fblogs.microsoft.co.il%2fblogs%2fbnaya%2farchive%2f2010%2f10%2f20%2fthe-hidden-assumption-of-ef-4-self-tracking-entity.aspx&amp;amp;title=The+hidden+assumption+of+EF+4+self-tracking+entity"&gt;&lt;img src="http://digg.com/img/badges/100x20-digg-button.png" width="100" height="20" alt="Digg This" title="Digg This" border="0" style="border:0;" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blogs.microsoft.co.il/aggbug.aspx?PostID=728677" width="1" height="1"&gt;</description><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/DEV/default.aspx">DEV</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/SELA/default.aspx">SELA</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/T4/default.aspx">T4</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/Entity+Framework/default.aspx">Entity Framework</category><category domain="http://blogs.microsoft.co.il/blogs/bnaya/archive/tags/EF/default.aspx">EF</category></item></channel></rss>