Wrox Programmer Forums
|
BOOK: Professional ASP.NET Design Patterns
This is the forum to discuss the Wrox book Professional ASP.NET Design Patterns by Scott Millett; ISBN: 978-0-470-29278-5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET Design Patterns section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 11th, 2010, 12:55 PM
Authorized User
 
Join Date: Dec 2010
Posts: 23
Thanks: 3
Thanked 2 Times in 2 Posts
Default Changes needed for Linq2Sql Repository?

Hi Scott,
Really enjoyed the book, great stuff.

I was wondering what changes would be needed to the code to use a Linq2Sql repository (or some other persistence technology like SubSonic, EntityFramework, etc). It seems that NHibernate does a very good job of letting you code "model first" using regular POCO objects, and the separation of concerns in the Agatha's code is great. However, Linq2Sql takes more of a "database-first" approach and generates classes/objects from your database schema. Is it still possible to use the Agatha's Storefront Model project/classes with a persistence mechanism other than NHibernate? If so, I'd be very interested to see what code changes would be needed.

I'm wondering if I should just bite the bullet and learn NHibernate, but I've been trying out Mindscape LightSpeed (http://www.mindscapehq.com/products/...d/default.aspx) and like it so far, and was curious how the Agatha's code might be different if it was not using NHibernate. Would the strict separation of layers not be possible with something other than NHib?

Thanks again for a great book.
 
Old December 14th, 2010, 10:16 AM
elbandit's Avatar
Wrox Author
 
Join Date: May 2007
Posts: 107
Thanks: 10
Thanked 17 Times in 15 Posts
Default

Hi ksouthworth,

Thanks the buying the book and taking time to post this question.

You can use EntityFramework and Linq2SQL in a code first manner, check out the code from chapter 7, here the entities are POCO and there is a Entity Framework and a NHibernate repository.

Here are some good videos on code first Entity Framework development:

Julie Lerman Domain Driven Entity Framework
http://tekpub.com/conferences/ndc201...tity-framework

Julie Lerman Entity Framework Persistance Ignorance
http://tekpub.com/conferences/ndc201...ance-ignorance

However you can still use database first and just use something like Linq2SQL as a strongly typed data access layer, a bit like this..

Code:
 
   public class CustomerRepository : ICustomerRepository
   {       
       public Customer FindBy(int id)
       {
           // Actual entity built code first
           Customer customerEntity = null;
 
           // Object created by Linq2SQL
           CustomerData customerDataTable = DataContextFactory
                          .GetDataContext().Customers
                          .FirstOrDefault<CustomerData>(c => c.Id == id);
 
           // If there is a matching object
           if (customerDataTable != null)           
           {
               // Create a Customer Entity from it
               customerEntity = ConvertIntoACustomerEntity(customerDataTable);
           }
           return customerEntity;
       }
 
       public Customer ConvertIntoACustomerEntity(CustomerData customerDataTable)
       {
           return new Customer()
                      {
                          Id = customerDataTable.Id,
                          Name = new Name(customerDataTable.FirstName, customerDataTable.LastName)
                      };
       }
   }
But this way you would have to create extra classes for lazy loading etc.

Unfortunately I haven't used SubSonic or Mindscape LightSpeed, but if it follows the Active Record pattern you should be able to use the same method as with Linq2SQL.

I am a couple of weeks away from adding an Entity Framework repository layer to the Agatha solution, plus replacing the QueryObjects with Linq Expression trees, as well as moving to a Command Query Responsibility Segregation type architecture so hopefully this will help you out.

Let me know if I have missed something or not answered ok.

Cheers
Scott
The Following User Says Thank You to elbandit For This Useful Post:
ksouthworth (December 17th, 2010)





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to convert Linq2SQL to Entity Framework? Gabor66 BOOK: Silverlight 4 Problem - Design - Solution 3 May 30th, 2011 07:32 AM
SVN Repository Hannes BOOK: Professional Joomla! ISBN: 978-0-470-13394-1 2 August 30th, 2010 05:17 AM
WebDAV repository custom realization zipfer Oracle 0 August 6th, 2007 08:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.