<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Coffee, smoke and techilicious burps at 3.47 AM</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/nilotpal/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/nilotpal/feed.xml</link>
    <description>Some half baked ideas by Nilotpal about Tao, Zen and the art of converting coffee into code...</description>
    <lastBuildDate>Wed, 17 Apr 2019 04:02:06 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>The last blog post...</title>
      <link>https://docs.microsoft.com/archive/blogs/nilotpal/the-last-blog-post</link>
      <pubDate>Fri, 20 Nov 2009 05:54:00 GMT</pubDate>
      <dc:creator><![CDATA[MSDN Archive]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nilotpal/2009/11/20/the-last-blog-post/</guid>
      <description><![CDATA[My last communique&nbsp;has always been quite&nbsp;important for me in all my previous...]]></description>
      <content:encoded><![CDATA[<P>My last communique&nbsp;has always been quite&nbsp;important for me in all my previous organizations. And I had thought that I would say something profound in my last&nbsp;email when I leave. But I could not think of anything&nbsp;and&nbsp;so no email.&nbsp;I still&nbsp;can't think of anything that would be super interesting so&nbsp;I guess I will keep it simple&nbsp;</P>
<P>This is going to be my last blog post here. I have resigned from Microsoft and am moving on to seek my future else where. I never thought this day would come and am myself quite surprised. </P>
<P>My experience with Microsoft was amazing. I am always going to remember this company as "The Company".&nbsp;However, I would like to add that there is definitely certain things that I expect to change in Microsoft IT, Hyderabad. </P>
<P>I would look forward to coming back to Microsoft some day, perhaps in a different role or capacity in a different division. And so I will not say Goodbye. I will just say "Bye for now" and hope to return some day. Until then I will continue to blog at <A href="https://www.dasboard.in/nilotpal">https://www.dasboard.in/nilotpal</A>. </P>]]></content:encoded>
    </item>
    <item>
      <title>Visual Studio 2008 Unit tests… Error loading *.vsmdi: *.vsmdi</title>
      <link>https://docs.microsoft.com/archive/blogs/nilotpal/visual-studio-2008-unit-tests-error-loading-vsmdi-vsmdi</link>
      <pubDate>Tue, 22 Sep 2009 09:03:15 GMT</pubDate>
      <dc:creator><![CDATA[MSDN Archive]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nilotpal/2009/09/22/visual-studio-2008-unit-tests-error-loading-vsmdi-vsmdi/</guid>
      <description><![CDATA[I got this error. I got no information on the internet as to how to get around it… 3 hours earlier:...]]></description>
      <content:encoded><![CDATA[<p align="justify"><font size="1">I got this error. I got no information on the internet as to how to get around it…</font></p> <p align="justify"><font size="1">3 hours earlier:</font></p> <p align="justify"><font size="1">I wanted to create a sequence diagram from the code I have already written. Visual Studio 2010 comes with the sequence diagram feature. I decided heck why not use it. It creates some really cool sequence diagrams. I opened the same project in Visual Studio 2010, created the sequence diagram, closed the project. Went for a smoke.</font></p> <p align="justify"><font size="1">30 minutes earlier:</font></p> <p align="justify"><font size="1">My test cases won’t run. the error I get is&nbsp; “Error loading xxx.vsmdi: D:\Projects\xxx\xxx.vsmdi” looked here, looked there looked everywhere. But didn’t look in the place I should have been looking.</font></p> <p align="justify"><font size="1">10 minutes earlier:</font></p> <p align="justify"><font size="1">I built the test project. I got an error. “Project file contains ToolsVersion="4.0", which is not supported by this version of MSBuild. Treating the project as if it had ToolsVersion="3.5".”</font></p> <p align="justify"><font size="1">Well I should have been looking at this 30 minutes ago. I went to the test projects Properties, went to TargetFramework and checked. it was not selected at all. I selected Framework 3.5.</font></p> <p align="justify"><font size="1">After this all I had to do was close the project and open it and then run all my tests in the solution.</font></p> <p align="justify"><font size="1">They were all still green. Love it when that happens…!!</font></p> <p><font size="1"></font></p>]]></content:encoded>
    </item>
    <item>
      <title>Left outer join in Entity Framework</title>
      <link>https://docs.microsoft.com/archive/blogs/nilotpal/left-outer-join-in-entity-framework</link>
      <pubDate>Tue, 18 Aug 2009 16:05:46 GMT</pubDate>
      <dc:creator><![CDATA[MSDN Archive]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nilotpal/2009/08/18/left-outer-join-in-entity-framework/</guid>
      <description><![CDATA[This evening I heard someone say that Left Outer Joins are not possible in Entity Framework or...]]></description>
      <content:encoded><![CDATA[<p align="justify">This evening I heard someone say that Left Outer Joins are not possible in Entity Framework or perhaps Left Outer Joins are possible, but they bring in all the data and then filter out the right table.</p> <p align="justify">I felt an urge to argue, but I resisted. I thought I would investigate before I waste time. I came up with some articles pretty quickly.</p> <ol> <li> <div align="justify"><a href="https://solidcoding.blogspot.com/2007/12/left-outer-join-in-linq.html">Left Outer Join in LINQ</a> </div> <li> <div align="justify"><a href="https://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/a3f2b146-750b-435c-b48c-2ea301bf130f/">Left Outer Join using Inverse Navigation Property</a> </div> <li> <div align="justify"><a href="https://blogs.microsoft.co.il/blogs/gilf/archive/2008/05/14/how-why-use-definingquery-element.aspx">DefiningQuery Element</a> </div> <li> <div align="justify"><a href="https://bhaidar.net/cs/archive/2007/08/01/left-outer-join-in-linq-to-sql.aspx">Left Outer Join in LINQ to SQL</a> </div> <li> <div align="justify"><a href="https://stackoverflow.com/questions/78468/linq-to-entity-with-multiple-left-outer-joins">LINQ to Entities with Multiple Left Outer Joins</a> </div></li></ol> <p align="justify">I am sure these should resolve all questions related to Left Outer Joins.</p> <p align="justify">Now about the performance and the question about how the data is brought, I am pretty sure we can prove that LINQ Queries all support deferred execution. But we can always prove that using the SQL Query Profiler.</p> <p align="justify">Hope this helps.</p>]]></content:encoded>
    </item>
    <item>
      <title>To query the local object context</title>
      <link>https://docs.microsoft.com/archive/blogs/nilotpal/to-query-the-local-object-context</link>
      <pubDate>Tue, 28 Jul 2009 01:49:41 GMT</pubDate>
      <dc:creator><![CDATA[MSDN Archive]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nilotpal/2009/07/28/to-query-the-local-object-context/</guid>
      <description><![CDATA[When faced with the dilemma that what if I wanted to insert something and before I actually saved...]]></description>
      <content:encoded><![CDATA[<p align="justify">When faced with the dilemma that what if I wanted to insert something and before I actually saved the changes into a persistent storage (database) by calling SaveAllChanges() method on the data context, I wanted to do a select, and also I wanted to make sure that this select is done on the just inserted objects, what should I be doing?</p> <p align="justify">Well generally we write a generic method that gets all the records for a generic object. it looks like this:</p><font size="2"> <p></p><font color="#2b91af" size="2"><font color="#2b91af" size="2">IQueryable</font></font><font size="2">&lt;T&gt; result = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">null</font></font><font size="2">;</font>  <p></p><font color="#0000ff" size="2"><font color="#0000ff" size="2">string</font></font><font size="2"> type = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">typeof</font></font><font size="2">(T).Name;</font>  <p></p> <p></p><font color="#008000" size="2"><font color="#008000" size="2">//ObjectQuery query = entities.CreateQuery&lt;T&gt;(type);</font></font></font><font size="2">  <p></p><font color="#2b91af" size="2"><font color="#2b91af" size="2">ObjectQuery</font></font><font size="2"> query = Context.CreateQuery&lt;T&gt;(type);</font>  <p>result = (</p><font color="#2b91af" size="2"><font color="#2b91af" size="2">IQueryable</font></font><font size="2">&lt;T&gt;)query; </font> <p></p><font color="#0000ff" size="2"><font color="#0000ff" size="2">return</font></font><font size="2"> result;</font></font>  <p align="justify">This will only query into the database. So if you have just recently inserted some records, but haven't yet committed them, they won’t appear in the results. </p> <p align="justify">However, if we provide another method (an overload perhaps) that handles local objects, this would be possible. When I say local objects, I mean objects that have been inserted into the Object Context and yet not been persisted into the database. this method would look something like this:</p><font color="#2b91af" size="2"><font color="#2b91af" size="2"> <p>IQueryable</p></font><font color="#000000" size="2">&lt;T&gt; result = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">null</font></font><font size="2"><font color="#000000">;</font></font>  <p></p><font color="#0000ff" size="2"><font color="#0000ff" size="2">string</font></font><font size="2"> type = </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">typeof</font></font><font size="2">(T).Name;</font>  <p></p><font color="#0000ff" size="2"><font color="#0000ff" size="2">return</font></font><font size="2"> </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">from</font></font><font size="2"> stateEntry </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">in</font></font><font size="2"> context.ObjectStateManager.GetObjectStateEntries(</font><font color="#2b91af" size="2"><font color="#2b91af" size="2">EntityState</font></font><font size="2">.Added |</font>  <p></p><font color="#2b91af" size="2"><font color="#2b91af" size="2">EntityState</font></font><font size="2">.Modified |</font>  <p></p><font color="#2b91af" size="2"><font color="#2b91af" size="2">EntityState</font></font><font size="2">.Unchanged)</font>  <p></p><font color="#0000ff" size="2"><font color="#0000ff" size="2">where</font></font><font size="2"> stateEntry.Entity != </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">null</font></font><font size="2"> &amp;&amp; stateEntry.EntitySet.Name == type</font>  <p></p><font color="#0000ff" size="2"><font color="#0000ff" size="2">select</font></font><font size="2"> stateEntry.Entity </font><font color="#0000ff" size="2"><font color="#0000ff" size="2">as</font></font><font size="2"> T;</font></font>  <p align="justify">This way we give the option to the user of the API to choose which kind of select he wants to fire. A local one or one on the database.</p>]]></content:encoded>
    </item>
    <item>
      <title>Your user profile was not loaded correctly! You have been logged on with a temporary profile.</title>
      <link>https://docs.microsoft.com/archive/blogs/nilotpal/your-user-profile-was-not-loaded-correctly-you-have-been-logged-on-with-a-temporary-profile</link>
      <pubDate>Wed, 22 Apr 2009 02:20:25 GMT</pubDate>
      <dc:creator><![CDATA[MSDN Archive]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nilotpal/2009/04/22/your-user-profile-was-not-loaded-correctly-you-have-been-logged-on-with-a-temporary-profile/</guid>
      <description><![CDATA[This is not a problem that I feel you would encounter on a regular basis. I think I had a unique...]]></description>
      <content:encoded><![CDATA[<p align="justify">This is not a problem that I feel you would encounter on a regular basis. I think I had a unique problem because of which I encountered this one. When you install an operating system it allows you to create a profile. Now I installed the machine at home. Which means I was not on the corpnet of Microsoft which means I could not log on to the domain. So when I created a profile named after my alias, it was considered as a local profile and not a domain profile. And a folder was created under “C:\Users” with my alias name.</p> <p align="justify">I am not sure if this makes any sense or not, but hey, I am a software program writer not a network administrator. So please excuse my jargon. Anyway, when I actually logged on to the domain with my brand new operating system the next day, a new profile had to be created for the domain. Now since there was a folder already with my alias name in “C:\Users” the brand new operating system create a brand new profile with in the format &lt;alias.domain&gt; so now there was a “.” in my profile directory name.</p> <p align="justify">What happens is this “.” sometimes creates problems in installing certain software. I got the error message saying “There is an invalid character in the directory path of My Documents”. I checked the path and could find only one anomaly. And no <em>points (“.”) </em>for guessing what.</p> <p align="justify">So I decided I will rename the profile directory. I straight away went to the directory and though I would rename it to something else. of course it wouldn’t let you. So I thought I would log on as a local administrator and then do it. Also I made sure that I start windows in safe mode.</p> <p align="justify">After Logging on I backup my documents, and delete the profile and assume that the next time I log on, it will automatically create the new directory for me. Guess what… Not that easy…</p> <p align="justify">So after a long research I found out that there are registry entries out of which windows reads the location of the profile directory. So if it doesn’t find the directory at the specified location, it creates a temporary directory and logs you on with a temporary profile. And after the log on is complete, it gives you that message.</p> <p align="justify">So here is what you do to save your life. Please do this only if you have already deleted your profile and did not take backup. If you are doing your research before you have messed with your machine, please skip these steps and refer below.</p> <ol> <li> <div align="justify">Log on with local administrator account, preferably in safe mode. To boot the machine in safe mode, Click F8 during boot. </div> <li> <div align="justify">Click Start + Run and type in regedit and then Enter. </div> <li> <div align="justify">Open HKEY_LOCAL_MACHINE </div> <li> <div align="justify">Open Software </div> <li> <div align="justify">Open Microsoft </div> <li> <div align="justify">Open Windows NT </div> <li> <div align="justify">Open Current Version </div> <li> <div align="justify">Open ProfileList </div> <li> <div align="justify">Here you will see keys that belong to each profile. To find your problematic profile navigate to each key and refer to the ProfileImagePath entry on the right hand side. </div> <li> <div align="justify">Once you find your problematic profile, just delete the key. This means delete the folder on the left hand side tree view that contains your alias in the ProfileImagePath entry. </div> <li> <div align="justify">Restart machine.</div></li></ol> <p align="justify">There is another way you can actually backup your profile and create a new one. </p> <p align="justify">Click on “Start”, Right click “Computer” and go to “properties”</p> <p align="justify">Click on “Change Settings”</p> <p align="justify"><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/nilotpal/WindowsLiveWriter/YouruserprofilewasnotloadedcorrectlyYou_A558/image_2.png" original-url="https://blogs.msdn.com/blogfiles/nilotpal/WindowsLiveWriter/YouruserprofilewasnotloadedcorrectlyYou_A558/image_2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/nilotpal/WindowsLiveWriter/YouruserprofilewasnotloadedcorrectlyYou_A558/image_thumb.png" original-url="https://blogs.msdn.com/blogfiles/nilotpal/WindowsLiveWriter/YouruserprofilewasnotloadedcorrectlyYou_A558/image_thumb.png" width="244" height="154"></a> </p> <p align="justify">Go to the “Advanced” tab and click on User Profiles “Settings” button</p> <p align="justify"><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/nilotpal/WindowsLiveWriter/YouruserprofilewasnotloadedcorrectlyYou_A558/image_4.png" original-url="https://blogs.msdn.com/blogfiles/nilotpal/WindowsLiveWriter/YouruserprofilewasnotloadedcorrectlyYou_A558/image_4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/nilotpal/WindowsLiveWriter/YouruserprofilewasnotloadedcorrectlyYou_A558/image_thumb_1.png" original-url="https://blogs.msdn.com/blogfiles/nilotpal/WindowsLiveWriter/YouruserprofilewasnotloadedcorrectlyYou_A558/image_thumb_1.png" width="220" height="244"></a> </p> <p align="justify"><a href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/nilotpal/WindowsLiveWriter/YouruserprofilewasnotloadedcorrectlyYou_A558/image_6.png" original-url="https://blogs.msdn.com/blogfiles/nilotpal/WindowsLiveWriter/YouruserprofilewasnotloadedcorrectlyYou_A558/image_6.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/nilotpal/WindowsLiveWriter/YouruserprofilewasnotloadedcorrectlyYou_A558/image_thumb_2.png" original-url="https://blogs.msdn.com/blogfiles/nilotpal/WindowsLiveWriter/YouruserprofilewasnotloadedcorrectlyYou_A558/image_thumb_2.png" width="233" height="244"></a> </p> <p align="justify">“Change type” will allow you to change your profile type between Roaming and Local Profiles</p> <p align="justify">“Delete” will delete that profile. Including the registry entries and everything.</p> <p align="justify">“Copy To” will back up your profile. It is always advisable to backup your profile from here rather than from anywhere else. Your profile contains more than you can see. Hidden Files, System Files, etc. This takes care of everything in a safe manner.</p> <p align="justify">Hope this helps.</p>]]></content:encoded>
    </item>
    <item>
      <title>Function Point Analysis (FPA) Glossary</title>
      <link>https://docs.microsoft.com/archive/blogs/nilotpal/function-point-analysis-fpa-glossary</link>
      <pubDate>Wed, 08 Apr 2009 09:04:12 GMT</pubDate>
      <dc:creator><![CDATA[MSDN Archive]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nilotpal/2009/04/08/function-point-analysis-fpa-glossary/</guid>
      <description><![CDATA[Internal Logical File (ILF): An internal logical file (ILF) is a user identifiable group of...]]></description>
      <content:encoded><![CDATA[<ol> <li> <div align="justify"><strong>Internal Logical File (ILF):</strong> An internal logical file (ILF) is a user identifiable group of logically related data or control information maintained within the boundary of the application. The primary intent of an ILF is to hold data maintained through one or more elementary processes of the application being counted.</div> <li> <div align="justify"><strong>External Interface File (EIF):</strong> An external interface file (EIF) is a user identifiable group of logically related data or control information referenced by the application, but maintained within the boundary of another application. The primary intent of an EIF is to hold data referenced through one or more elementary processes within the boundary of the application counted. This means an EIF counted for an application must be in an ILF in another application.</div> <li> <div align="justify"><strong>Data Element Type (DET): </strong>A data element type (DET) is a unique, user-recognizable, non-repeated field.</div> <li> <div align="justify"><strong>Record Element Type (RET): </strong>A record element type (RET) is a user-recognizable subgroup of data elements within an ILF or EIF.</div> <li> <div align="justify"><strong>File Type Referenced (FTR):</strong> FTR's are the combined number of Internal Logical Files (ILF's) referenced or updated and External Interface Files referenced</div> <li> <div align="justify"><strong>External Input (EI): </strong>An external input (EI) is an elementary process that processes data or control information that comes from outside the application’s boundary. the primary intent of an EI is to maintain one or more ILFs and/or to alter the behavior of the system.</div> <li> <div align="justify"><strong>External Output (EO):</strong> An external output (EO) is an elementary process that sends data or control information outside the application’s boundary. the primary intent of an external output is to present information to a user through processing logic other than or in addition to the retrieval of data or control information. The processing logic must contain at least one mathematical formula or calculation, or create derived data. An external output may also maintain one or more ILFs and/or alter the behavior of the system.”</div> <li> <div align="justify"><strong>External Inquiry (EQ):</strong> An external inquiry (EQ) is an elementary process that sends data or control information outside the application boundary. The primary intent of an external inquiry is to present information to a user through the retrieval of data or control information. The processing logic contains no mathematical formula or calculation, and creates no derived data. No ILF is maintained during the processing, nor is the behavior of the system altered.</div> <li> <div align="justify"><strong>General System Characteristics (GSC):</strong> The data and transactional functions discussed in earlier chapters together represent the total business functions that are delivered through the application being counted. Truly this is the logical representation of the functionality and does not address the physical implementation of the functions in an IT environment. The FPA method of IFPUG has captured the critical implementation features of typical applications through 14 general system characteristics. These encompass almost all the major implementation complexities that can exist, and through careful evaluation of each of the GSCs, the estimator can arrive at final function point count that includes logical as well as physical implementation properties of the application being counted.</div> <li> <div align="justify"><strong>Value Adjustment Factor (VAF):</strong> Calculated ((Total Degree of Influence * 0.01) + 0.65)</div> <li> <div align="justify"><strong>Calibration Factor (CF):</strong> general buffer depending upon practical environment</div> <li> <div align="justify"><strong>Delivery Rate (DR):</strong> No. of function points a single developer will accomplish every month</div> <li> <div align="justify"><strong>Days per person month (DPM):</strong> The no. of days a person will effectively work in a month. 20 working days in a month and Microsoft generally counts 75% utilization which means around 15 working days in a month.</div></li></ol>]]></content:encoded>
    </item>
    <item>
      <title>Update an entity in Repository Pattern</title>
      <link>https://docs.microsoft.com/archive/blogs/nilotpal/update-an-entity-in-repository-pattern</link>
      <pubDate>Tue, 17 Mar 2009 09:08:41 GMT</pubDate>
      <dc:creator><![CDATA[MSDN Archive]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nilotpal/2009/03/17/update-an-entity-in-repository-pattern/</guid>
      <description><![CDATA[Look around the web. You will find no Update method in the repository patterns for entity framework...]]></description>
      <content:encoded><![CDATA[<p>Look around the web. You will find no Update method in the repository patterns for entity framework implementations published. There are different flavors of retrieves, mark for insertions an deletions but no update implementation. And curiously this is the most painful. There are 2 options that you have. But to explain both, I will start off with the repository design. We can get into a discussion about the pattern in case anyone is interested, all you have to do is instigate me by posting a comment.</p> <p><img src="https://blogs.infosupport.com/photos/willemm/images/14346/original.aspx" width="649" height="508"></p> <p>&nbsp;</p> <p>So now your IRepository here has some generic functions :</p> <p>---</p> <p><span class="code-SummaryComment">&nbsp;&nbsp;&nbsp; ///</span><span class="code-comment"> <span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">summary</span><span class="code-SummaryComment">&gt;</span></span> <br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> Return all instances of type T.</span> <br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> <span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">/</span><span class="code-SummaryComment">summary</span><span class="code-SummaryComment">&gt;</span></span> <br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> <span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">returns</span><span class="code-SummaryComment">&gt;</span><span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">/</span><span class="code-SummaryComment">returns</span><span class="code-SummaryComment">&gt;</span></span> <br>&nbsp;&nbsp;&nbsp; IEnumerable<span class="code-keyword">&lt;</span>T<span class="code-keyword">&gt;</span> All(); <br><br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> <span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">summary</span><span class="code-SummaryComment">&gt;</span></span> <br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> Return all instances of type T that match the expression exp.</span> <br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> <span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">/</span><span class="code-SummaryComment">summary</span><span class="code-SummaryComment">&gt;</span></span> <br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> <span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">param</span> <span class="code-SummaryComment">name="exp"</span><span class="code-SummaryComment">&gt;</span><span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">/</span><span class="code-SummaryComment">param</span><span class="code-SummaryComment">&gt;</span></span> <br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> <span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">returns</span><span class="code-SummaryComment">&gt;</span><span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">/</span><span class="code-SummaryComment">returns</span><span class="code-SummaryComment">&gt;</span></span> <br>&nbsp;&nbsp;&nbsp; IEnumerable<span class="code-keyword">&lt;</span>T<span class="code-keyword">&gt;</span> FindAll(Func<span class="code-keyword">&lt;</span>T, <span class="code-keyword">bool</span><span class="code-keyword">&gt;</span> exp); <br><br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> <span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">summary</span><span class="code-SummaryComment">&gt;</span>Returns the single entity matching the expression. Throws an exception if there is not exactly one such entity.<span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">/</span><span class="code-SummaryComment">summary</span><span class="code-SummaryComment">&gt;</span></span> <br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> <span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">param</span> <span class="code-SummaryComment">name="exp"</span><span class="code-SummaryComment">&gt;</span><span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">/</span><span class="code-SummaryComment">param</span><span class="code-SummaryComment">&gt;</span><span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">returns</span><span class="code-SummaryComment">&gt;</span><span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">/</span><span class="code-SummaryComment">returns</span><span class="code-SummaryComment">&gt;</span></span> <br>&nbsp;&nbsp;&nbsp; T <span class="code-SDKkeyword">Single</span>(Func<span class="code-keyword">&lt;</span>T, <span class="code-keyword">bool</span><span class="code-keyword">&gt;</span> exp); <br><br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> <span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">summary</span><span class="code-SummaryComment">&gt;</span>Returns the first element satisfying the condition.<span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">/</span><span class="code-SummaryComment">summary</span><span class="code-SummaryComment">&gt;</span></span> <br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> <span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">param</span> <span class="code-SummaryComment">name="exp"</span><span class="code-SummaryComment">&gt;</span><span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">/</span><span class="code-SummaryComment">param</span><span class="code-SummaryComment">&gt;</span><span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">returns</span><span class="code-SummaryComment">&gt;</span><span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">/</span><span class="code-SummaryComment">returns</span><span class="code-SummaryComment">&gt;</span></span> <br>&nbsp;&nbsp;&nbsp; T First(Func<span class="code-keyword">&lt;</span>T, <span class="code-keyword">bool</span><span class="code-keyword">&gt;</span> exp); <br><br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> <span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">summary</span><span class="code-SummaryComment">&gt;</span></span> <br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> Mark an entity to be deleted when the context is saved.</span> <br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> <span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">/</span><span class="code-SummaryComment">summary</span><span class="code-SummaryComment">&gt;</span></span> <br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> <span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">param</span> <span class="code-SummaryComment">name="entity"</span><span class="code-SummaryComment">&gt;</span><span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">/</span><span class="code-SummaryComment">param</span><span class="code-SummaryComment">&gt;</span></span> <br>&nbsp;&nbsp;&nbsp; <span class="code-keyword">void</span> MarkForDeletion(T entity); <br><br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> <span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">summary</span><span class="code-SummaryComment">&gt;</span></span> <br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> Create a new instance of type T.</span> <br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> <span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">/</span><span class="code-SummaryComment">summary</span><span class="code-SummaryComment">&gt;</span></span> <br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> <span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">returns</span><span class="code-SummaryComment">&gt;</span><span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">/</span><span class="code-SummaryComment">returns</span><span class="code-SummaryComment">&gt;</span></span> <br>&nbsp;&nbsp;&nbsp; T CreateInstance(); <br><br>&nbsp;&nbsp;&nbsp; <span class="code-SummaryComment">///</span><span class="code-comment"> <span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">summary</span><span class="code-SummaryComment">&gt;</span>Persist the data context.<span class="code-SummaryComment">&lt;</span><span class="code-SummaryComment">/</span><span class="code-SummaryComment">summary</span><span class="code-SummaryComment">&gt;</span></span> <br>&nbsp;&nbsp;&nbsp; <span class="code-keyword">void</span> SaveAll();</p> <p>---</p> <p>These generic functions, if you notice, does not contain an update function. Now the 2 options that you have that I have talked about, are</p> <p>Option 1: Do not take care of your updates in the provider. Now this is simple. Do all the updates in the logical layer that calls the data provider. Something like</p> <p>---</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Events dbEvent = null; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IEnumerable&lt;Events&gt; dbEvents = this.DataProvider.All&lt;Events&gt;(eve =&gt; eve.EventID.Equals(communityEvent.EventID)); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (dbEvents != null &amp;&amp; dbEvents.Count() == 1) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbEvent = dbEvents.SingleOrDefault(); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new ApplicationException(MADConstants.GENERIC_DATA_ERROR); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbEvent.DateModified = communityEvent.DateModified; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbEvent.Description = communityEvent.Description; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbEvent.EventEndDate = communityEvent.EventEndDate; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbEvent.EventName = communityEvent.EventName; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbEvent.EventStartDate = communityEvent.EventStartDate; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbEvent.IsApproved = communityEvent.IsApproved; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbEvent.LastModifiedBy = communityEvent.LastModifiedBy; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbEvent.NoOfRatings = communityEvent.NoOfRatings; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbEvent.Organizer = communityEvent.Organizer; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbEvent.ParticipatedBy = communityEvent.ParticipatedBy; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbEvent.RatedBy = communityEvent.RatedBy; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbEvent.Rating = communityEvent.Rating; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dbEvent.Sessions = communityEvent.Sessions; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.DataProvider.SaveAllChanges(); <br></p> <p>---</p> <p>The second option which i feel is most elegant is this:</p> <p>---</p> <p>/// &lt;summary&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// Updates <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;typeparam name="T"&gt;&lt;/typeparam&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;param name="entityName"&gt;&lt;/param&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;param name="entity"&gt;&lt;/param&gt; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public void Update&lt;T&gt;(string entityName, T entity) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; this.context.AttachTo(entityName, entity); <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; } </p> <p>---</p> <p>So all you have to do now is to call the functions like this</p> <p>---</p> <p>DataProvider.Update&lt;Customer&gt;(“Customer”, customer);</p> <p>DataProvider.SaveAllchanges();</p> <p>---</p> <p>The third option is a little complex. Please refer to the diagram above, the task repositories that you will implement must contain the update function like this:</p> <p>public void Update(Customer customer) </p> <p>{ <br>&nbsp;&nbsp;&nbsp; context.<b>Attach(customer)</b>; //Custom extensor method <br>&nbsp;&nbsp;&nbsp; context.<b>SaveChanges();</b> <br>}</p> <p>This means you have all your Task Repositories that know the type of your entity. So a CustomerRepository would know that it is handling Customer Types and hence will take Customer as a parameter to the Update Method. This is because Attach method requires an argument that is of type System.Data.Objects.DataClasses.IEntityWithKey. Which means it will not accept type T because this does not have the entity key or the primary key on the basis of which it will know which entity / row to update in the database.</p> <p>The purpose of the third option is that all interaction with the database that is specific to a particular entity can be handled in the Task Repositories.</p>]]></content:encoded>
    </item>
    <item>
      <title>Repository Pattern – The purpose</title>
      <link>https://docs.microsoft.com/archive/blogs/nilotpal/repository-pattern-the-purpose</link>
      <pubDate>Mon, 16 Mar 2009 20:30:05 GMT</pubDate>
      <dc:creator><![CDATA[MSDN Archive]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nilotpal/2009/03/16/repository-pattern-the-purpose/</guid>
      <description><![CDATA[We decided to implement the repository pattern for the Entity Framework Implementation in our...]]></description>
      <content:encoded><![CDATA[<p align="justify">We decided to implement the repository pattern for the Entity Framework Implementation in our project. So last couple of weeks people have been asking me why the repository pattern is required. I mean what is it that this pattern does besides giving a layer of abstraction, and providing the CRUD methods, which are also available in C# as a language feature (LINQ).</p> <p align="justify">The answer is given aptly by Martin Fowler as, “A system with a complex domain model often benefits from a layer, such as the one provided by Data Mapper (165), that isolates domain objects from details of the database access code. In such systems it can be worthwhile to build another layer of abstraction over the mapping layer where query construction code is concentrated. This becomes more important when there are a large number of domain classes or heavy querying. In these cases particularly, adding this layer helps minimize duplicate query logic.</p> <p align="justify">A Repository mediates between the domain and data mapping layers, acting like an in-memory domain object collection. Client objects construct query specifications declaratively and submit them to Repository for satisfaction. Objects can be added to and removed from the Repository, as they can from a simple collection of objects, and the mapping code encapsulated by the Repository will carry out the appropriate operations behind the scenes. Conceptually, a Repository encapsulates the set of objects persisted in a data store and the operations performed over them, providing a more object-oriented view of the persistence layer. Repository also supports the objective of achieving a clean separation and one-way dependency between the domain and data mapping layers.”  <p align="justify">This has a no. of benefits. Simplifying complexity, removing redundant querying, making code more testable, etc. Let’s say you want to test your code without going into the database and destroying it completely. unless you use DBUnit, This pattern helps you a lot. All you need to do is change your SaveChanges() function from  <p align="justify">---  <p align="justify">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;summary&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// Saves all changes in the current context.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public virtual int SaveAllChanges()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ((ObjectContext)this.Context).SaveChanges();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return -1;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br></p> <p align="justify">---  <p align="justify">to  <p align="justify">---  <p align="justify">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;summary&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// Saves all changes in the current context.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /// &lt;/summary&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public virtual int SaveAllChanges()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br></p> <p align="justify">---</p> <p align="justify">On doing this, your changes are not populated to the database and you can do all your testing in-memory. Now is it a good idea to change your code to just make it testable? Well that’s a good question that needs discussing at length. Maybe in another post…</p>]]></content:encoded>
    </item>
    <item>
      <title>Function Import and Loading of referenced data</title>
      <link>https://docs.microsoft.com/archive/blogs/nilotpal/function-import-and-loading-of-referenced-data</link>
      <pubDate>Fri, 20 Feb 2009 01:44:44 GMT</pubDate>
      <dc:creator><![CDATA[MSDN Archive]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nilotpal/2009/02/20/function-import-and-loading-of-referenced-data/</guid>
      <description><![CDATA[Why do Entity Framework Function Imports do not have eager loading? Because when you use Entity SQL...]]></description>
      <content:encoded><![CDATA[<p>Why do Entity Framework Function Imports do not have eager loading? Because when you use Entity SQL or regular Object context to retrieve data, it is a live connection. So whenever you say eager loading enabled, it gets the data from the database using the live connection. But if you want to do it using Function Import, EF doesn’t know where to get the data from, since the stored procedure that the function import maps to, doesn’t get that data. Perhaps in the later versions of EF, the team might add the feature which can mix and match the object context and the stored procedure to get the required data. But as of now it is not possible.</p>]]></content:encoded>
    </item>
    <item>
      <title>Are you Eager? Or are you Lazy? Or are you both on a case to case basis...??</title>
      <link>https://docs.microsoft.com/archive/blogs/nilotpal/are-you-eager-or-are-you-lazy-or-are-you-both-on-a-case-to-case-basis</link>
      <pubDate>Wed, 28 Jan 2009 10:24:00 GMT</pubDate>
      <dc:creator><![CDATA[MSDN Archive]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/nilotpal/2009/01/28/are-you-eager-or-are-you-lazy-or-are-you-both-on-a-case-to-case-basis/</guid>
      <description><![CDATA[Entity Framework, Eager Loading and Lazy Loading, my own 2 cents. For those new to Entity Framework,...]]></description>
      <content:encoded><![CDATA[<P align=justify>Entity Framework, Eager Loading and Lazy Loading, my own 2 cents. For those new to Entity Framework, we are talking about the patterns that you can use to load related objects. The strategy by which you would load entity objects that are related to the one in question. There is a <A href="https://msdn.microsoft.com/en-us/library/dd196179.aspx" mce_href="https://msdn.microsoft.com/en-us/library/dd196179.aspx">beautiful resource</A> that mentions it all. I do not think there is any elaboration required in that matter. But this is not the meat of the matter.</P>
<P align=justify><A href="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/nilotpal/WindowsLiveWriter/AreyouEagerOrareyouLazyOrareyoubothonac_11608/image_2.png" original-url="https://blogs.msdn.com/blogfiles/nilotpal/WindowsLiveWriter/AreyouEagerOrareyouLazyOrareyoubothonac_11608/image_2.png" mce_href="https://blogs.msdn.com/blogfiles/nilotpal/WindowsLiveWriter/AreyouEagerOrareyouLazyOrareyoubothonac_11608/image_2.png"><IMG style="BORDER-RIGHT-WIDTH: 0px; MARGIN: 0px 10px 0px 0px; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" border=0 alt=image align=left src="https://msdnshared.blob.core.windows.net/media/TNBlogsFS/BlogFileStorage/blogs_msdn/nilotpal/WindowsLiveWriter/AreyouEagerOrareyouLazyOrareyoubothonac_11608/image_thumb.png" original-url="https://blogs.msdn.com/blogfiles/nilotpal/WindowsLiveWriter/AreyouEagerOrareyouLazyOrareyoubothonac_11608/image_thumb.png" width=217 height=244 mce_src="https://blogs.msdn.com/blogfiles/nilotpal/WindowsLiveWriter/AreyouEagerOrareyouLazyOrareyoubothonac_11608/image_thumb.png"></A> How do you design an application that uses Entity Framework as a data access strategy? There are a no. of things to consider. The apparent answer all over the Internet is the Repository Pattern (ref: <A href="https://blogs.infosupport.com/blogs/willemm/archive/2008/08/18/Using-ADO.NET-Entity-framework-with-the-repository-pattern.aspx" mce_href="https://blogs.infosupport.com/blogs/willemm/archive/2008/08/18/Using-ADO.NET-Entity-framework-with-the-repository-pattern.aspx">https://blogs.infosupport.com/blogs/willemm/archive/2008/08/18/Using-ADO.NET-Entity-framework-with-the-repository-pattern.aspx</A>, <A href="https://blogs.microsoft.co.il/blogs/kim/archive/2008/11/12/data-access-with-the-entity-framework.aspx" mce_href="https://blogs.microsoft.co.il/blogs/kim/archive/2008/11/12/data-access-with-the-entity-framework.aspx">https://blogs.microsoft.co.il/blogs/kim/archive/2008/11/12/data-access-with-the-entity-framework.aspx</A>, <A href="https://www.simonsegal.net/blog/2009/01/13/entity-framework-repository-specifications-and-fetching-strategies/" mce_href="https://www.simonsegal.net/blog/2009/01/13/entity-framework-repository-specifications-and-fetching-strategies/">https://www.simonsegal.net/blog/2009/01/13/entity-framework-repository-specifications-and-fetching-strategies/</A>). The <A href="https://martinfowler.com/eaaCatalog/repository.html" mce_href="https://martinfowler.com/eaaCatalog/repository.html">purpose of the repository</A> pattern is "A system with a complex domain model often benefits from a layer, such as the one provided by Data Mapper (165), that isolates domain objects from details of the database access code." All said and done, we write the repository to abstract the CRUD from the Application Layer. This way, simply put, we don't need to write separate routines to do CRUD behaviour on every entity type. The functions look something like this:</P>
<P align=justify>------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</P><FONT size=2>
<BLOCKQUOTE>
<P mce_keep="true">&nbsp;</P><FONT color=#808080 size=2><FONT color=#808080 size=2>///</FONT></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2> </FONT></FONT><FONT color=#808080 size=2><FONT color=#808080 size=2>&lt;summary&gt; <BR></FONT></FONT><FONT color=#808080 size=2><FONT color=#808080 size=2>///</FONT></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2> Returns the required querable object to the caller <BR></FONT></FONT><FONT color=#808080 size=2><FONT color=#808080 size=2>///</FONT></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2> </FONT></FONT><FONT color=#808080 size=2><FONT color=#808080 size=2>&lt;/summary&gt; <BR></FONT></FONT><FONT color=#808080 size=2><FONT color=#808080 size=2>///</FONT></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2> </FONT></FONT><FONT color=#808080 size=2><FONT color=#808080 size=2>&lt;typeparam name="T"&gt;</FONT></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>Generic Object</FONT></FONT><FONT color=#808080 size=2><FONT color=#808080 size=2>&lt;/typeparam&gt;&nbsp;<BR></FONT></FONT><FONT color=#808080 size=2><FONT color=#808080 size=2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ///</FONT></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2> </FONT></FONT><FONT color=#808080 size=2><FONT color=#808080 size=2>&lt;returns&gt;</FONT></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>IQueryable</FONT></FONT><FONT size=2><FONT color=#808080 size=2>&lt;T&gt;&lt;/returns&gt;&nbsp;<BR></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT>private</FONT></FONT><FONT size=2> </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>IQueryable</FONT></FONT><FONT size=2>&lt;T&gt; GetTable&lt;T&gt;()&nbsp;<BR><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT>{&nbsp;<BR></FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT>&nbsp;&nbsp;&nbsp;&nbsp; IQueryable</FONT></FONT><FONT size=2>&lt;T&gt; result = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>null</FONT></FONT><FONT size=2>;&nbsp;<BR></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT>&nbsp;&nbsp;&nbsp;&nbsp; string</FONT></FONT><FONT size=2> type = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>typeof</FONT></FONT><FONT size=2>(T).Name;&nbsp;&nbsp;<BR><FONT color=#0000ff><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT></FONT></FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>ObjectQuery</FONT></FONT><FONT size=2> query = Context.CreateQuery&lt;T&gt;(type);&nbsp;<BR><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT>result = (</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>IQueryable</FONT></FONT><FONT size=2>&lt;T&gt;)query;&nbsp;<BR><FONT color=#0000ff>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT></FONT><FONT size=2><FONT color=#0000ff size=2>return</FONT></FONT><FONT size=2> result;&nbsp;<BR><FONT color=#808080>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT></FONT><FONT size=2>}</FONT></BLOCKQUOTE>
<P><FONT size=2>This routine is called like this.</FONT></P><FONT size=2><FONT size=2>
<P mce_keep="true">&nbsp;</P><FONT color=#008000 size=2><FONT color=#008000 size=2>////&lt;summary&gt; <BR></FONT></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>////Return all instances of type T. <BR></FONT></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>////&lt;/summary&gt; <BR></FONT></FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>////&lt;returns&gt;&lt;/returns&gt; <BR></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>public</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>virtual</FONT></FONT><FONT size=2> </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>IEnumerable</FONT></FONT><FONT size=2>&lt;T&gt; All&lt;T&gt;() <BR>{ <BR>&nbsp;&nbsp;&nbsp;&nbsp; System.Data.Linq.</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>DataLoadOptions</FONT></FONT><FONT size=2> dlo = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>new</FONT></FONT><FONT size=2> System.Data.Linq.</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>DataLoadOptions</FONT></FONT><FONT size=2>(); <BR></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp;&nbsp; return</FONT></FONT><FONT size=2> GetTable&lt;T&gt;(); <BR>}</FONT></FONT> 
<P><FONT size=2>And this in turn is called like this:</FONT></P><FONT size=2><FONT size=2>
<P mce_keep="true">&nbsp;</P><FONT color=#0000ff size=2><FONT color=#0000ff size=2>public</FONT></FONT><FONT size=2> </FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>IEnumerable</FONT></FONT><FONT size=2>&lt;</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>Employee</FONT></FONT><FONT size=2>&gt; GetEmployees() <BR>{ <BR></FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>&nbsp;&nbsp;&nbsp;&nbsp; IEnumerable</FONT></FONT><FONT size=2>&lt;</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>Employee</FONT></FONT><FONT size=2>&gt; employees = </FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>this</FONT></FONT><FONT size=2>.dbProvider.All&lt;</FONT><FONT color=#2b91af size=2><FONT color=#2b91af size=2>Employee</FONT></FONT><FONT size=2>&gt;(); <BR></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>&nbsp;&nbsp;&nbsp;&nbsp; return</FONT></FONT><FONT size=2> employees; <BR>}</FONT></FONT></FONT></FONT></FONT> 
<P align=justify>---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</P>
<P align=justify>Now if you see, we have one function retrieve all types of entity objects. Now let's get to the actual topic in hand. Eager loading and lazy loading. I cannot opt for any of the <A href="https://msdn.microsoft.com/en-us/library/dd196179.aspx" mce_href="https://msdn.microsoft.com/en-us/library/dd196179.aspx">mentioned</A> patterns, because I do not have the type of the pattern that I am going to return at design time. I have already postponed that by using Generics. Just last night I learnt from <A href="https://blogs.msdn.com/dsimmons" mce_href="https://blogs.msdn.com/dsimmons">Daniel Simmons</A> that Framework 4.0 they are planning to add a property to Context object in order to opt in implicit lazy loading. </P>
<P align=justify>While I am still trying to figure out a good way of working around eager loading and lazy loading, as of now (before 4.0 arrives) I am firing separate queries to get all types of related objects. And interestingly, once I fire the queries for the related objects and enumerate them, the principal object at hand gets populated with related objects. So next time you want to reference the related objects, just go ahead and use the beautiful sentence completion features such as this: "txtAddressLine1.Text = employee.EmployeeAddress.First().Address.AddressLine1;"</P>]]></content:encoded>
    </item>
  </channel>
</rss>