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

  • Home
  • SEARCH
  • 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 5840757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:47:44+00:00 2026-05-22T11:47:44+00:00

I have 2 lists. A shopping cart list, which contains a objects with the

  • 0

I have 2 lists. A shopping cart list, which contains a objects with the properties; Quantity and ProductId. I then get all products from the repository (IQueryable) that has ProductId in the shopping cart list. This means that for every product, there is a shopping cart object with the Quantity related to it.

When doing the select, I want to assign this Quantity also, but the only way I know to do this is to query the cart again.

For egx.

        model = (from p in productService.GetAllProducts()
                              where cart.Entries.Select(c => c.ProductId).Contains(p.ProductId)
                              select new CartViewItem
                                         {
                                             Price = p.Price,
                                             ProductId = p.ProductId,
                                             ProductName = p.ProductName,
                                             Quantity = cart.Entries.FirstOrDefault(c => c.ProductId == p.ProductId).Quantity
                                         }).ToList();

Model:

public class ShoppingCartEntry
{
    public int ProductId { get; set; }
    public int Quantity { get; set; }
}

cart.Entries is not coming from a repository. productService.GetAllProducts() returns an entityframework’s IQueryable.

EDIT: My new code is:

        model= (from p in productService.GetAllProducts()
                              from c in cart.Entries
                              where c.ProductId == p.ProductId
                              select new CartViewItem
                                         {
                                             Price = p.Price,
                                             ProductId = p.ProductId,
                                             ProductName = p.ProductName,
                                             Quantity = c.Quantity
                                         }).ToList();

This throws an error:
Unable to create a constant value of type 'SampleApp.WebUI.Models.ShoppingCartEntry'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.

  • 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-22T11:47:44+00:00Added an answer on May 22, 2026 at 11:47 am

    i think this should work…

    var model = (from c in cart.Entires  // The small local cart collection
                 let cpid = cart.Entires.Select(c2 => c2.ProjectId) // 
                 from p in productService.GetAllProducts() // Query all Products used in cart
                                   .Where(queryp => cpid.Contains(queryp.ProjectId)).ToList()
                 where p.ProductId == c.ProductId
                 select new CartViewItem {
                     p.Price,
                     p.ProductId,
                     p.Brand,
                     p.ProductName,
                     Discount = p.DiscountPercent * c.Quantity}).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two lists of objects. Each list is already sorted by a property
I have two unsorted lists and I need to produce another list which is
I have a header.html which start with session_start();. Then the following code, $_SESSION['cart'][$sw_id] is
I have two lists of custom objects and want to update a field for
I have two classes: Media and Container. I have two lists List<Media> and List<Container>
I have two Sharepoint lists: - Assignments - Activities The activities list has a
I'm constructing an ecommerce application in Symfony, and I have a page which lists
Simple setup: Shopping Cart in the form of a data list. Header has two
I have some delphi code which, given a list of items, calculates the total
I'm using a web service which returns a list of products. I created a

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.