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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:30:30+00:00 2026-05-14T18:30:30+00:00

I have a DataContext object, called CodeLookupAccessDataContext, that was generated through the Visual Studio

  • 0

I have a DataContext object, called “CodeLookupAccessDataContext”, that was generated through the Visual Studio LINQ to SQL class wizard. I extended the functionality of this object such that it exposes some methods to return results of LINQ to SQL queries. Here are the methods I have defined:

public List<CompositeSIDMap> lookupCompositeSIDMap(int regionId, int marketId)
{
    var sidGroupId = CompositeSIDGroupMaps.Where(x => x.RegionID.Equals(regionId) && x.MarketID.Equals(marketId))
        .Select(x => x.CompositeSIDGroup);

    IEnumerator<int> sidGroupIdEnum = sidGroupId.GetEnumerator();

    if (sidGroupIdEnum.MoveNext())
        return lookupCodeInfo<CompositeSIDMap, CompositeSIDMap>(x => x.CompositeSIDGroup.Equals(sidGroupIdEnum.Current), x => x);
    else
        return null;
}

private List<TResult> lookupCodeInfo<T, TResult>(Func<T, bool> compLambda, Func<T, TResult> selectLambda)
    where T : class
{
    System.Data.Linq.Table<T> dataTable = this.GetTable<T>();

    var codeQueryResult = dataTable.Where(compLambda)
        .Select(selectLambda);

    List<TResult> codeList = new List<TResult>();
    foreach (TResult row in codeQueryResult)
        codeList.Add(row);

    return codeList;
}

CompositeSIDGroupMap and CompositeSIDMap are both tables in our database that are represented as objects in my DataContext object. I wrote the following code to call these methods and display the T-SQL generated after calling these methods:

using (CodeLookupAccessDataContext codeLookup = new CodeLookupAccessDataContext())
{
    codeLookup.Log = Console.Out;
    List<CompositeSIDMap> compList = codeLookup.lookupCompositeSIDMap(regionId, marketId);
}

I got the following results in my log after invoking this code:

SELECT [t0].[CompositeSIDGroup]
FROM [dbo].[CompositeSIDGroupMap] AS [t0]
WHERE ([t0].[RegionID] = @p0) AND ([t0].[MarketID] = @p1)
-- @p0: Input Int (Size = 0; Prec = 0; Scale = 0) [5]
-- @p1: Input Int (Size = 0; Prec = 0; Scale = 0) [3]
-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30729.1

SELECT [t0].[PK_CSM], [t0].[CompositeSIDGroup], [t0].[InputSID], [t0].[TargetSID], [t0].[StartOffset], [t0].[EndOffset], [t0].[Scale]
FROM [dbo].[CompositeSIDMap] AS [t0]
-- Context: SqlProvider(Sql2005) Model: AttributedMetaModel Build: 3.5.30729.1

The first T-SQL statement contains a where clause as specified and returns one column as expected. However, the second statement is missing a where clause and returns all columns, even though I did specify which rows I wanted to view and which columns were of interest. Why is the second T-SQL statement generated the way it is, and what should I do to ensure that I filter out the data according to specifications via the T-SQL?

Also note that I would prefer to keep lookupCodeInfo() and especially am interested in keeping it enabled to accept lambda functions for specifying which rows/columns to return.

UPDATE

This discussion might also be of interest.

  • 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-14T18:30:31+00:00Added an answer on May 14, 2026 at 6:30 pm

    The problem is that the function

    private List<TResult> lookupCodeInfo<T, TResult>(Func<T, bool> compLambda, 
                                                     Func<T, TResult> selectLambda)
    

    accepts Func<...> arguments, which will make the lambdas compiled into functions. The Linq-to-sql SQL generator cannot translate a compiled function to SQL, but will rather perform the filtering and projection in memory.

    Change your lookupCodeInfo to take Expression<...> instead, which will preserve them as expression trees that linq-to-sql can traverse.

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

Sidebar

Ask A Question

Stats

  • Questions 399k
  • Answers 399k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer JSON is very lightweight which makes it better suited for… May 15, 2026 at 3:50 am
  • Editorial Team
    Editorial Team added an answer You are done. Gigabyte transfer and WSE 3.0 never worked… May 15, 2026 at 3:50 am
  • Editorial Team
    Editorial Team added an answer String is a custom class with a static function ListIntegers.… May 15, 2026 at 3:50 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.