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 7946329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:07:04+00:00 2026-06-04T01:07:04+00:00

Maybe I’m going about this the wrong way… I have an Order table and

  • 0

Maybe I’m going about this the wrong way…

I have an Order table and an OrderItem table. I create a new Order using linq2sql generated classes.

I then attempt to get all orderable items out of my database using a query that goes after various tables.

I try to then create a new list of OrderItem from that query, but it squawks that I can’t explicitly create the object.

Explicit construction of entity type OrderItem in query is not allowed.

Here is the query:

return (from im in dc.MasterItems
                    join c in dc.Categories
                      on im.CATEGORY equals c.CATEGORY1                      
                    select new OrderItem()
                    {
                        OrderItemId = im.ItemId
                    });

The idea is to populate the database with all orderable items when a new order is created, and then display them in a grid for updates. I’m taking the results of that query and attempting to use AddRange on Order.OrderItems

Is there a proper strategy for accomplishing this using linq2sql?

Thanks in advance for your help.

  • 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-06-04T01:07:05+00:00Added an answer on June 4, 2026 at 1:07 am

    From my understanding of L2S, I don’t think you can use explicit construction (in other words new SomeObj() { ... }) in a query because you aren’t enumerating the results yet. In other words, the query has just been built, so how are you supposed to do this:

    SELECT new OrderItem() FROM MasterItems im JOIN Categories c on c.CATEGORY1 = im.CATEGORY
    

    This is what you’re trying to do, which doesn’t work because you can’t return a POCO (unless you join the OrderItem back somehow and do OrderItem.* somewhere). Ultimately, what you would have to do is just enumerate the collection (either in a foreach loop or by calling ToList()) on the query first and then build your OrderItem objects.

    var query = (from im in dc.MasterItems
                        join c in dc.Categories
                          on im.CATEGORY equals c.CATEGORY1                      
                        select new { MasterItem = im, Category = c});
    List<OrderItem> returnItems = new List<OrderItem>();
    foreach(var item in query)
    {
        returnItems.Add(new OrderItem() { OrderItemId = item.MasterItem.ItemId });
    }
    return returnItems;
    

    OR

    return (from im in dc.MasterItems
                        join c in dc.Categories
                          on im.CATEGORY equals c.CATEGORY1                      
                        select new { MasterItem = im, Category = c})
        .ToList()
        .Select(tr => new OrderItem() { OrderItemId = tr.MasterItem.ItemId });
    

    Try that out and let me know if that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Maybe I'm going about it the wrong way. Here is what I'm trying to
Maybe due to the fact I'm relatively new to R, I have problems using
Maybe this is very basic, but I am all confused. I have a simple
Maybe I am being stupid, but this isn't making sense to me... I have
Maybe this is something I am just missing, but is there any way to
maybe i am understanding it all wrong but as i understood the best way
Maybe this is a dumb question! I'm just wandering is there any way/web part
maybe this is a stupid question, but i have seen many Tuts that build
Maybe there is a package to do this, but I have not been able
Maybe this question is kind of silly but I have no clue how to

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.