Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > Other ASP.NET > BOOK: Professional ASP.NET Design Patterns
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.
Reply With Quote
  #2 (permalink)  
Old December 14th, 2010, 10:16 AM
elbandit's Avatar
Wrox Author
Points: 599, Level: 8
Points: 599, Level: 8 Points: 599, Level: 8 Points: 599, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: May 2007
Location: Southsea, Portsmouth, Hampshire, United Kingdom.
Posts: 107
Thanks: 10
Thanked 17 Times in 15 Posts

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

Julie Lerman Entity Framework Persistance 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..

   public class CustomerRepository : ICustomerRepository
       public Customer FindBy(int id)
           // Actual entity built code first
           Customer customerEntity = null;
           // Object created by Linq2SQL
           CustomerData customerDataTable = DataContextFactory
                          .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.

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 12:20 AM.

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