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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:53:41+00:00 2026-05-25T05:53:41+00:00

Have been working mainly on java and new to LINQ so I need some

  • 0

Have been working mainly on java and new to LINQ so I need some suggestion regarding performance of this query .I have 3 tables

1. Products  -->                   ProductID | Name | Price | VendorID
2. Category  -->                   CategoryID | Label
3. SubCategory-->                  SubCategoryID | Label | ParentID
4. Product_SubCategory_Mapping-->  ProductID | SubCategoryID 
5. Vendor     -->                  VendorID | VendorName

I want to select all products from product table along with its Vendors for any given subcategory .Should following query work fine ? Or it needs any optimization ?

var list =  (from p in Products 
             join cat in Product_SubCategory_Mapping 
             on p.UserId equals cat.UserId 
             join sub in SubCategories 
             on cat.SubCategoryId equals sub.SubCategoryId
             where sub.CategoryId == 19 && CustomFunction(p.ID) > 100 
             select new { p, p.Vendor, trend = CustomFunction(p.ID) })
             .Skip((pageNum - 1) * pageSize)
             .Take(pageSize);

I will be creating a custom class that will match result of query .

  1. Is creating a view/Stored procedure a better scenario in case like this ?
  2. Can CustomFunction(p.ID)>100 be named so function is not called twice ? Its a custom function in Database.
  3. For paging will Skip and take perform well ?
  • 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-25T05:53:41+00:00Added an answer on May 25, 2026 at 5:53 am

    You’re on the right track, but LINQ to SQL won’t understand CustomFunction() so you’ll need to switch to LINQ to Objects with AsEnumerable() before you can call it. You can also use let to capture the result of CustomFunction() once for use elsewhere in the query:

    var listFromSql = from p in Products
                      join cat in Product_SubCategory_Mapping
                        on p.UserId equals cat.UserId
                      join sub in SubCategories
                        on cat.SubCategoryId equals sub.SubCategoryId
                      where sub.CategoryId == 19
                      select p;
    
    var list = from p in listFromSql.AsEnumerable()
               let trend = CustomFunction(p.ID)
               where trend > 100
               select new { p, p.Vendor, trend };
    

    Update: To answer your listed questions:

    1. This is relatively straightforward SQL, so what L2SQL generates should be fine. You can use L2SQL logging or SQL Profiler to confirm that the SQL is good enough.
    2. See let above.
    3. Skip() and Take() on an IQueryable<> (like listFromSql above) will translate into the appropriate SQL, limiting the result set sent across the wire. Skip() and Take() on an IEnumerable<> just enumerate the sequence to get the requested results, but operate on the full result set returned from SQL.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a brand new Java developer (I have been working in asp.net) and
Okay this one has me stumped.. mainly because i have been working on this
I have been working on some legacy C++ code that uses variable length structures
I have been working with Struts for some time, but for a project I
For the last five or more years I have been working mainly on ongoing,
I've been working with a developer on a web-based application. I have some experience
I've been professionally working with Java application servers for five years, but I have
I've been considering the idea of working on some open source projects, mainly because
I have been working on a web services related project for about the last
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)

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.