<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Using Repository and Unit of Work patterns with Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx</link><description>If you have been watching this blog, you know that I have been discussing the various aspects of POCO capabilities we added to Entity Framework 4.0. POCO support makes it possible to do persistence ignorance with Entity Framework in a way that was never</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Using Repository and Unit of Work patterns with Entity Framework 4.0 | ASP.NET MVC</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9765517</link><pubDate>Wed, 17 Jun 2009 06:46:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9765517</guid><dc:creator>Using Repository and Unit of Work patterns with Entity Framework 4.0 | ASP.NET MVC</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://aspmvc.co.cc/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-40/"&gt;http://aspmvc.co.cc/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-40/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Using Repository and Unit of Work patterns with Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9765527</link><pubDate>Wed, 17 Jun 2009 06:52:35 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9765527</guid><dc:creator>Rvy</dc:creator><description>&lt;p&gt;Whats wrong with the transactionscope approach? or Why is the UnitOfWork better?&lt;/p&gt;
</description></item><item><title>Visual Studio 2010 EF4 POCO Part2</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9766640</link><pubDate>Wed, 17 Jun 2009 08:32:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9766640</guid><dc:creator>雲のごとく</dc:creator><description>&lt;p&gt;前回 は EF4 で追加される予定の POCO を解説しました。 V1 ではエンティティをデータ層として利用すべきか、ドメイン層で利用すべきか、という白熱した？？議論がありました。 EF4 では POCO&lt;/p&gt;
</description></item><item><title>ADO.NET team blog : Using Repository and Unit of Work patterns with Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9766671</link><pubDate>Wed, 17 Jun 2009 08:39:52 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9766671</guid><dc:creator>9eFish</dc:creator><description>&lt;p&gt;9efish.感谢你的文章 - Trackback from 9eFish&lt;/p&gt;
</description></item><item><title>re: Using Repository and Unit of Work patterns with Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9768642</link><pubDate>Wed, 17 Jun 2009 11:04:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9768642</guid><dc:creator>Roger Rudin</dc:creator><description>&lt;p&gt;This post covers the basic patterns used when applying Domain-driven design DDD.&lt;/p&gt;
&lt;p&gt;Domain-driven design provides a set of pattern to define domain objects and to access them in a simple way.&lt;/p&gt;
&lt;p&gt;Working with Domain-driven design sets the focus on the domain so you try to learn as much as possible about the domain and you try to put that new knowledge into the code. It avoids the gaps between business expert and developer.&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://domaindrivendesign.org/resources/what_is_ddd"&gt;http://domaindrivendesign.org/resources/what_is_ddd&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In the last 2 years, I have been working with the newest .Net technologies (Entity Framework 3.5 and Linq2Sql) and methodologies (DDD Patterns) to find a way to simplify the creation of Data Access Layers.&lt;/p&gt;
&lt;p&gt;The result of my work is a common library that supports the developer in the folowing steps in creating a flexible Data Access Layer (DAL) &lt;/p&gt;
&lt;p&gt;- Simplifies the using of an ORM&lt;/p&gt;
&lt;p&gt;- Uses LINQ for querying data &lt;/p&gt;
&lt;p&gt;- Supports DDD patterns &lt;/p&gt;
&lt;p&gt;- Enables and simplifies TDD&lt;/p&gt;
&lt;p&gt;- Expandable by any data source supporting Linq&lt;/p&gt;
&lt;p&gt;- Supports Linq2Entities and L2Sql (NHibernate support planned)&lt;/p&gt;
&lt;p&gt;- Enhances missing functionalities to EF and Linq2Sql&lt;/p&gt;
&lt;p&gt;If you are interested in that library and if you are familiar with DDD, you are free to use this library to combine the newest ADO .Net technology with the DDD pattern.&lt;/p&gt;
&lt;p&gt;You can download the library under the following link: &lt;a rel="nofollow" target="_new" href="http://sourceforge.net/project/showfiles.php?group_id=242039&amp;amp;package_id=319519"&gt;http://sourceforge.net/project/showfiles.php?group_id=242039&amp;amp;package_id=319519&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://sourceforge.net/projects/bbvcommon/"&gt;http://sourceforge.net/projects/bbvcommon/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Using Repository and Unit of Work patterns with Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9768780</link><pubDate>Wed, 17 Jun 2009 11:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9768780</guid><dc:creator>Keith Patton</dc:creator><description>&lt;p&gt;Hi, &lt;/p&gt;
&lt;p&gt;If you have this as the first line then there is little point in abstracting away a repository or unit of work to be honest as you have a direct dependency on the object context and therefore the EF. You should also use some form of injection to abstract away the repository and unit of work implementation?&lt;/p&gt;
&lt;p&gt;IUnitOfWork unitOfWork = new NorthwindContext();&lt;/p&gt;
</description></item><item><title>re: Using Repository and Unit of Work patterns with Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9769018</link><pubDate>Wed, 17 Jun 2009 13:35:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9769018</guid><dc:creator>Dennis van der Stelt</dc:creator><description>&lt;p&gt;There's no attachment to the post&lt;/p&gt;
</description></item><item><title>re: Using Repository and Unit of Work patterns with Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9769040</link><pubDate>Wed, 17 Jun 2009 13:46:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9769040</guid><dc:creator>Moke</dc:creator><description>&lt;p&gt;There is another example of this available here: &lt;a rel="nofollow" target="_new" href="http://devtalk.dk/2009/06/09/Entity+Framework+40+Beta+1+POCO+ObjectSet+Repository+And+UnitOfWork.aspx"&gt;http://devtalk.dk/2009/06/09/Entity+Framework+40+Beta+1+POCO+ObjectSet+Repository+And+UnitOfWork.aspx&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Using Repository and Unit of Work patterns with Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9792429</link><pubDate>Sat, 20 Jun 2009 03:10:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9792429</guid><dc:creator>Marcelo</dc:creator><description>&lt;p&gt;Hi&lt;/p&gt;
&lt;p&gt;A question:&lt;/p&gt;
&lt;p&gt;If I have two or more changes pending, I need use &amp;quot;begin transaction&amp;quot; before call Context.SaveChanges() or it is not necesary ?&lt;/p&gt;
</description></item><item><title>Использование паттернов Repository и Unit of Work в Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9795142</link><pubDate>Sun, 21 Jun 2009 13:21:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9795142</guid><dc:creator>progg.ru</dc:creator><description>&lt;p&gt;Thank you for submitting this cool story - Trackback from progg.ru&lt;/p&gt;
</description></item><item><title>re: Using Repository and Unit of Work patterns with Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9797670</link><pubDate>Mon, 22 Jun 2009 17:00:22 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9797670</guid><dc:creator>Dragos V.</dc:creator><description>&lt;p&gt;You should use interfaces for the repository variables&lt;/p&gt;
&lt;p&gt;CustomerRepository customerRepository = new CustomerRepository(unitOfWork);&lt;/p&gt;
&lt;p&gt;should be &lt;/p&gt;
&lt;p&gt;ICustomerRepository customerRepository = new CustomerRepository(unitOfWork);&lt;/p&gt;
</description></item><item><title>re: Using Repository and Unit of Work patterns with Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9798010</link><pubDate>Mon, 22 Jun 2009 20:31:34 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9798010</guid><dc:creator>chaz</dc:creator><description>&lt;p&gt;First of all thanks for the post. &amp;nbsp;I have a question regarding your use of the Repository pattern. &amp;nbsp;If I understand correctly the purpose of the Repository is to map between your DAL and LOB to ensure true persistance ignorance. &amp;nbsp;But if you return an instance of an EF Entity object as in the example below;&lt;/p&gt;
&lt;p&gt;&amp;quot; &amp;nbsp; &amp;nbsp;public Customer GetCustomerById(string id) &amp;nbsp; &amp;nbsp;{ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return _context.Customers.Where(c =&amp;gt; c.CustomerID == id).Single(); &amp;nbsp; &amp;nbsp;}&amp;quot;&lt;/p&gt;
&lt;p&gt;Isn't that defeating the purpose of the pattern? &amp;nbsp;Why introduce the extra layer of abstraction at this point? &amp;nbsp;&lt;/p&gt;
</description></item><item><title>re: Using Repository and Unit of Work patterns with Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9799202</link><pubDate>Tue, 23 Jun 2009 14:08:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9799202</guid><dc:creator>JasonBSteele</dc:creator><description>&lt;p&gt;@Keith Patton - you probably already know this but for anyone else wondering about your comment on IUnitOfWork unitOfWork = new NorthwindContext();&lt;/p&gt;
&lt;p&gt;I guess its left to the reader to use an IoC container of ther choice rather than explitly creating a NorthwindContext. For example Unity would let you configure a mapping for IUnitOfWork to the concrete NorthwindContext.&lt;/p&gt;
&lt;p&gt;Of course this should also probably be extended to include the Repositiries.&lt;/p&gt;
</description></item><item><title>re: Using Repository and Unit of Work patterns with Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9801675</link><pubDate>Wed, 24 Jun 2009 19:13:48 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9801675</guid><dc:creator>James Alexander</dc:creator><description>&lt;p&gt;@chaz He isn't necessarily returning an entity object (or type deriving from the Entity base class). The Customer type is simply a POCO and works well w/ EF4 due to it's new support for true POCO.&lt;/p&gt;
</description></item><item><title>re: Using Repository and Unit of Work patterns with Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9856067</link><pubDate>Mon, 03 Aug 2009 12:43:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9856067</guid><dc:creator>Ashraf</dc:creator><description>&lt;p&gt;-- why we need exlicit unit of work class, where we have unit of work implemented built-in to EF?&lt;/p&gt;
</description></item><item><title>re: Using Repository and Unit of Work patterns with Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9898908</link><pubDate>Thu, 24 Sep 2009 14:51:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9898908</guid><dc:creator>jinyen</dc:creator><description>&lt;p&gt;your sample code below, how would you do this using dependency injection?&lt;/p&gt;
&lt;p&gt;IUnitOfWork unitOfWork = new NorthwindContext();CustomerRepository customerRepository = new CustomerRepository(unitOfWork);Customer customer = customerRepository.GetCustomerById(&amp;quot;ALFKI&amp;quot;);ProductRepository productRepository = new ProductRepository(unitOfWork);Product product = productRepository.GetById(1);OrderRepository orderRepository = new OrderRepository(unitOfWork);Order order = new Order(customer); order.AddNewOrderDetail(product, 1); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;orderRepository.AddOrder(order);unitOfWork.Save();&lt;/p&gt;
</description></item><item><title>re: Using Repository and Unit of Work patterns with Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9921198</link><pubDate>Thu, 12 Nov 2009 06:09:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9921198</guid><dc:creator>Jarod Ferguson</dc:creator><description>&lt;p&gt;@jinyen&lt;/p&gt;
&lt;p&gt;You would inject IUnitOfWork, ICustomerRepository and IProductRepository into your application layer object, e.g a Controller, Presenter or Service. (preferably through the ctor)&lt;/p&gt;
&lt;p&gt;The key would be to configre the lifetime of the UOW to be per request. This way each repo will use the same UOW/transaction.&lt;/p&gt;
&lt;p&gt;You may choose to let the UOW be handled by the infrastructure layer, and not inject it at all. If the request is good, it will commit/save, else it will rollback. (you shouldnt have to deal with that really)&lt;/p&gt;
</description></item><item><title>re: Using Repository and Unit of Work patterns with Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9921199</link><pubDate>Thu, 12 Nov 2009 06:10:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9921199</guid><dc:creator>Jarod Ferguson</dc:creator><description>&lt;p&gt;@jinyen&lt;/p&gt;
&lt;p&gt;You would inject IUnitOfWork, ICustomerRepository and IProductRepository into your application layer object, e.g a Controller, Presenter or Service. (preferably through the ctor)&lt;/p&gt;
&lt;p&gt;The key would be to configure the lifetime of the UOW to be per request. This way each repo will use the same UOW/transaction.&lt;/p&gt;
&lt;p&gt;You may choose to let the UOW be handled by the infrastructure layer, and not inject it at all. If the request is good, it will commit/save, else it will rollback. (you shouldnt have to deal with that really)&lt;/p&gt;
</description></item><item><title>re: Using Repository and Unit of Work patterns with Entity Framework 4.0</title><link>http://blogs.msdn.com/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx#9941941</link><pubDate>Tue, 29 Dec 2009 15:28:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9941941</guid><dc:creator>syd</dc:creator><description>&lt;p&gt;So this will work as a transaction?&lt;/p&gt;
&lt;p&gt;IUnitOfWork unitOfWork = new NorthwindContext();CustomerRepository customerRepository = new CustomerRepository(unitOfWork);Customer customer = customerRepository.GetCustomerById(&amp;quot;ALFKI&amp;quot;);ProductRepository productRepository = new ProductRepository(unitOfWork);Product product = productRepository.GetById(1);OrderRepository orderRepository = new OrderRepository(unitOfWork);Order order = new Order(customer); order.AddNewOrderDetail(product, 1); &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;orderRepository.AddOrder(order);unitOfWork.Save();&lt;/p&gt;
&lt;p&gt;Everything will be rollback if something goes wrong?&lt;/p&gt;
</description></item></channel></rss>