Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 692645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:40:20+00:00 2026-05-14T02:40:20+00:00

In my repository layer I am mapping Linq-to-Sql objects to my application domain objects.

  • 0

In my repository layer I am mapping Linq-to-Sql objects to my application domain objects. The code below shows how I am doing this for a complex object, product:

        public IQueryable<Product> Products {
        get 
        {
            var result = from p in _db.Products
                         let images = GetProductImages(p.ProductID)
                         select new Product {
                             Id = p.ProductID,
                             SKU = p.SKU,
                             Name = p.Name,
                             ShortDescription = p.ShortDescription,
                             Description = p.Description,
                             Price = p.Price,
                             Weight = p.Weight,
                             StockQuantity = p.StockQuantity,
                             IsAvailable = p.IsAvailable,
                             AllowBackOrder = p.AllowBackOrder,
                             PageMetaData = ConvertXmlToDictionary(p.PageMetaData),
                             Images = new LazyList<ProductImage>(images)
                         };
            return result;
        }
    }

This works great for any child objects (e.g. Images).

However, everything is not so smooth when saving my product. As I am not using the Linq objects, presumably I lose any object tracking.

Therefore in an ideal world I would execute the following in my service layer:

Image productImage = new Image(params…);
product.Images.Add(productImage);
_myservice.SaveProduct(product);

To implement this in my repository I would need to loop through each Image object in the Images property of my Product domain object, check to see if it exists and then add or update the image.

This seems a lot of work if I just want to add one image.

Of course I could do something like:

Image productImage = new Image(params…);
_myservice.AddProductImage(product.Id, productImage);

which would be more efficient (since I can add the Image and then the product/image mapping record) but is not as nice as the first example.

What would you recommend? Since my application is still in the early stages of development would it be worthwhile to start looking at EF 4.0 since I would lose the need to have to map my domain objects in this way?

Thanks,
Ben

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T02:40:20+00:00Added an answer on May 14, 2026 at 2:40 am

    I was helping a colleague with a similar problem last week. Our solution was to remove the direct association between a product and it’s image. Instead, we provided a seperate query (not a lazy list) to load the image. This is because in our model the joins necessary to retrieve the image was too much of a performance hit.

    We now have something like:

    _myservice.GetProduct(id);
    _myservice.GetImagesForProduct(id);
    

    As far as editing the product, you don’t necessarily need to do all the editing at once. Why not have one edit for product information, and another edit for images?

    _myservice.Update(productId, parameters);
    _myservice.AddImageToProduct(productId, image);
    _myservice.RemoveImageFromProduct(productId, imageId);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my project I have my Linq To SQL dbml file, A Repository Layer
So for namespacing my repository layer, it's easy. I do something like this: The
I have this sort of format asp.net MVC View -> Service Layer -> Repository.
As per my previous question: Rhino Mocks - Testing Repository layer returns "object reference
Repository pattern is used to abstract from particular database and object-relation-mapping technology(like EF) used.
This is concerning an enterprise application with a very generic database (all objects are
I have a repository implemented using LINQ to SQL. I need to do Unit
I am using a repository design with web applications (repository (data layer) exposing model
I have the standard repository pattern with a service layer and I need to
I am using a standard repository pattern with a service layer which calls the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.