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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:47:00+00:00 2026-05-31T10:47:00+00:00

I didn’t plan project correctly from beginning so I ended up having many SQL

  • 0

I didn’t plan project correctly from beginning so I ended up having many SQL Queries scatterd around page.

So to avoid catching Sql exceptions in every other method or missing half of page due to exception in one of methods I want to pull all the data I need so :

This is method from dll file, I need to return it so I can work with objects after context dispose but I am doing something awfully wrong (first query finalproduct returns empty):

 public static Tuple<Product, IEnumerable<Tag>, IEnumerable<ProductComment>, IEnumerable<ProductVote>, IEnumerable<Review>, IEnumerable<ReviewComment>, IEnumerable<ReviewVote>> GetBigProduct(int productID)    
            {
                using (ProductClassesDataContext context = new ProductClassesDataContext())
                {
                    var outproduct = from product in context.Products
                                     where product.ID == productID
                                     join producttag in context.ProductTags on product.ID equals producttag.productID
                                     join tag in context.Tags on producttag.TagID equals tag.ID
                                     join productComment in context.ProductComments on product.ID equals productComment.productID
                                     join productVote in context.ProductVotes on product.ID equals productVote.productID
                                     join review in context.Reviews on product.ID equals review.productID
                                     join reviewComment in context.ReviewComments on review.ID equals reviewComment.reviewID
                                     join reviewVote in context.ReviewVotes on review.ID equals reviewVote.reviewID
                                     select new Tuple<Product, Tag, ProductComment, ProductVote, Review, ReviewComment, ReviewVote>
                                                     (product, tag, productComment, productVote, review, reviewComment, reviewVote);


                    var finalProduct = (from t in outproduct select t.Item1).Single();

                    var finalTags = (from t in outproduct select t.Item2).ToList();

                    var finalProductComments = (from t in outproduct select t.Item3).ToList();

                    var finalProductVotes = (from t in outproduct select t.Item4).ToList();

                    var finalReviews = (from t in outproduct select t.Item5).ToList();

                    var finalReviewsComments = (from t in outproduct select t.Item6).ToList();

                    var finalReviewsVotes = (from t in outproduct select t.Item7).ToList();

                    return new Tuple<Product, IEnumerable<Tag>, IEnumerable<ProductComment>, IEnumerable<ProductVote>, IEnumerable<Review>, IEnumerable<ReviewComment>, IEnumerable<ReviewVote>>
                               (finalProduct, finalTags, finalProductComments, finalProductVotes, finalReviews, finalReviewsComments, finalReviewsVotes);
                }
            }
  • 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-31T10:47:02+00:00Added an answer on May 31, 2026 at 10:47 am

    Are you sure there is only one element returned by from t in outproduct select t.Item1 query?
    According to documentation, Single():

    Returns the only element of a sequence, and throws an exception if
    there is not exactly one element in the sequence.

    You may need First() or FirstOrDefault() instead.

    Update after comments

    I think the problem is with your joins. Actually, I don’t think you want to do joins here. What you need, I guess, is something like following:

    var outproduct = from product in context.Products
                     where product.ID == productID
                     select new Tuple<Product, ProductComment, Tag>(
                          product, // product itself
                          context.ProductComments.Where(p => p.productID == product.ID).ToList(), // list of comments for this product
                          (from pt in context.ProductTags
                          join tag in context.Tags on pt.TagID equals tag.ID
                          where pt.productID = product.ID
                          select tag).ToList() // list of tags for this product
                          // ... more dimensions in tuple
                     );
    

    Then you will get, out of outproduct query, a collection of of tuples containing <Product, List of ProductComments, List of Tags>.
    You can easily add rest of your tuple dimensions. I removed them for simplicity.

    You can now returns this tuple directly from your function doing just

    return outproduct.FirstOfDefault()
    

    There is no need for your var finalProduct =-style lines and rebuilding the final tuple.

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

Sidebar

Related Questions

Didn't find any from their website. I mostly just trying to see which one
I didn't see a clear answer from the same question How can I figure
I didn't find anywhere whether is possible to query from Db4o all objects implementing
I didn't get the result I want from the following code: Private Sub tblView_SelectionChanged(ByVal
Why didn't StarTeam 2008 Release 2 Client install correctly on my machine? Whenever I
I didn't see any license information on top of a web page's source code.
I didn't find any documentation as to why XPath support was dropped from jQuery
I didn't know. just saw it in my debug window a BOOLEAN from STORAGE_DEVICE_DESCRIPTOR
I didn't get the answer to this anywhere. What is the runtime complexity of
I didn't see any similar questions asked on this topic, and I had 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.