<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Entity Framework on InternetException</title><link>https://internetexception.com/categories/entity-framework/</link><description>Recent content in Entity Framework on InternetException</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Mon, 24 Oct 2022 15:02:09 +0200</lastBuildDate><atom:link href="https://internetexception.com/categories/entity-framework/index.xml" rel="self" type="application/rss+xml"/><item><title>Entity Framework: Change Tracking</title><link>https://internetexception.com/2022/10/24/entity-framework-change-tracking/</link><pubDate>Mon, 24 Oct 2022 15:02:09 +0200</pubDate><guid>https://internetexception.com/2022/10/24/entity-framework-change-tracking/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;tracked entities are saved during &lt;code&gt;SaveChanges()&lt;/code&gt; call&lt;/li&gt;&#10;&lt;li&gt;entities being tracked when they are:&#10;&lt;ul&gt;&#10;&lt;li&gt;returned from DB&lt;/li&gt;&#10;&lt;li&gt;attached to context&lt;/li&gt;&#10;&lt;li&gt;added as subentity&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;tracking can be disabled (&lt;code&gt;AsNoTracking()&lt;/code&gt; i.e.)&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;&#10;&lt;p&gt;&lt;a href="https://learn.microsoft.com/en-us/ef/core/change-tracking/" target="_blank" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/ef/core/change-tracking/&lt;/a&gt;&#10;&lt;/p&gt;</description></item><item><title>Entity Framework: eager and lazy loading</title><link>https://internetexception.com/2022/10/24/entity-framework-eager-and-lazy-loading/</link><pubDate>Mon, 24 Oct 2022 14:57:56 +0200</pubDate><guid>https://internetexception.com/2022/10/24/entity-framework-eager-and-lazy-loading/</guid><description>&lt;ul&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;lazy loading:&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;delaying load of data until we specifically request for it&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;!-- --&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;i.e. accessing &lt;code&gt;customer.Address&lt;/code&gt; loads Address of a customer in the background via separate SQL query&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;!-- --&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;property needs to be public, virtual&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;!-- --&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;context.Configuration.ProxyCreationEnabled should be true&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;!-- --&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;context.Configuration.LazyLoadingEnabled should be true&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;!-- --&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;to disable lazy loading completely &lt;code&gt;Context.Configuration.LazyLoadingEnabled = false;&lt;/code&gt;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;li&gt;&#10;&lt;p&gt;eager loading&lt;/p&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;opposite of lazy loading&lt;/li&gt;&#10;&lt;li&gt;loads related entities as part of the query&lt;/li&gt;&#10;&lt;li&gt;done via &lt;code&gt;.Include()&lt;/code&gt; query&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;p&gt;Further read:&lt;/p&gt;</description></item><item><title>Mapping collection of entities in EF with AutoMapper</title><link>https://internetexception.com/2013/05/25/mapping-collection-of-entities-in-ef-with-automapper/</link><pubDate>Sat, 25 May 2013 11:38:00 +0200</pubDate><guid>https://internetexception.com/2013/05/25/mapping-collection-of-entities-in-ef-with-automapper/</guid><description>&lt;p&gt;In my &lt;a href="https://internetexception.com/2013/05/16/entity-framework-and-base-entity-class/"&gt;last post&lt;/a&gt;&#10; I explained why is useful to add base entity class in EF. Today I will write how with use of this base class an AutoMapped map collection of data objects (i.e. DTOs to existing collection of entities).&lt;/p&gt;</description></item><item><title>Entity Framework and Base Entity class</title><link>https://internetexception.com/2013/05/16/entity-framework-and-base-entity-class/</link><pubDate>Thu, 16 May 2013 14:32:00 +0200</pubDate><guid>https://internetexception.com/2013/05/16/entity-framework-and-base-entity-class/</guid><description>&lt;p&gt;Entity Framework does great job with taking care of entities changes and entities collection internally. And its uses almost plain POCO objects. Almost because collections of dependents data like in 1 to many tables relationship needs virtual keyword. Its understandable since EF needs to track what happens to collection. For instance lets have 2 tables: Customer and dependent Order. &lt;a class="img-zoom" href="https://internetexception.com/wp-content/uploads/2013/05/customer_order.png"&gt;&lt;img&#10; src="https://internetexception.com/wp-content/uploads/2013/05/customer_order.png"&#10; alt=""&#10; &#10; loading="lazy" decoding="async"&gt;&lt;/a&gt;&lt;/p&gt;</description></item><item><title>Ninject and Entity Framework</title><link>https://internetexception.com/2013/05/03/ninject-and-entity-framework/</link><pubDate>Fri, 03 May 2013 03:50:00 +0200</pubDate><guid>https://internetexception.com/2013/05/03/ninject-and-entity-framework/</guid><description>&lt;p&gt;&lt;a href="https://internetexception.com/2013/04/23/entity-framework-patterns-extension-and-unit-test-in-visual-studio-2012/" target="_blank" rel="noopener noreferrer"&gt;Last time&lt;/a&gt; I wrote about problem with testing Entity Framework in Visual Studio 2012. During working on this project I also encounter problems with configuration of Ninject to allow injecting Entity Framework classes from its Patterns extension. To be frankly this was not much a problem then lack of documentation. I just was forced to experiment with Ninject and new-thing-for-me Entity Framework Patterns extension.&lt;/p&gt;</description></item><item><title>Entity Framework Patterns extension and Unit Test in Visual Studio 2012</title><link>https://internetexception.com/2013/04/23/entity-framework-patterns-extension-and-unit-test-in-visual-studio-2012/</link><pubDate>Tue, 23 Apr 2013 02:18:00 +0200</pubDate><guid>https://internetexception.com/2013/04/23/entity-framework-patterns-extension-and-unit-test-in-visual-studio-2012/</guid><description>&lt;p&gt;Yesterday I was trying to make work simple test class in VS2012. I did not know what was wrong exactly. It was first project when I tried to glue together Entity Framework with repository pattern and Ninject as IoC container. Because of the fact that this was first time for solution like that I was sure that it is me, or rather source of my problem was indeed my code. But let&amp;rsquo;s not skip ahead.&lt;/p&gt;</description></item></channel></rss>