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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:14:50+00:00 2026-05-11T19:14:50+00:00

I’m in the process of speeding up Linq to SQL queries in a web

  • 0

I’m in the process of speeding up Linq to SQL queries in a web app by converting them to Compiled queries and I ran into a problem converting a very simple statement.

I want to compile a simple statement that uses the following parameters to get valid employees from the database:

TestParams myParams = new TestParams
{
    ValidEmps = new int[] { 1, 2, 3 }
};

Here is the working query:

IQueryable<Employees> MySelectedEmps =
    from emps in db.Employees
    where myParams.ValidEmps.Contains(emps.EmployeeID)
    select emps;

Here is my attempt at compiling it:

private static Func<MyDataContext, TestParams, IQueryable<Employee>> myCompiledQuery =
    CompiledQuery.Compile((MyDataContext db, TestParams myParams) =>
        from emps in db.Employees
        where myParams.ValidEmps.Contains(emps.EmployeeID)
        select emps);

This statement with compile and build, but when I run it, I receive the following run time error:

Comparison operators not supported for
type ‘System.Int32[]’

I have also tried passing a List and an IEnumerable with the same error message.

I have also tried replacing the .Contains statement with a .Any(valemp => valemp == emps.EmployeeID) statement but I still get the same error.

Is it possible to have a compiled query that uses the equivalent of the SQL “IN” statement? What am I doing wrong?

  • 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-11T19:14:50+00:00Added an answer on May 11, 2026 at 7:14 pm

    call a stored procedure, and pass in a CVS list of values, using this method:

    Before you use my function, you need to set up a “helper” table, you only need to do this one time per database:

    CREATE TABLE Numbers
    (Number int  NOT NULL,
        CONSTRAINT PK_Numbers PRIMARY KEY CLUSTERED (Number ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    DECLARE @x int
    SET @x=0
    WHILE @x<8000
    BEGIN
        SET @x=@x+1
        INSERT INTO Numbers VALUES (@x)
    END
    

    use this function to split your string, which does not loop and is very fast:

    CREATE FUNCTION [dbo].[FN_ListToTable]
    (
         @SplitOn              char(1)              --REQUIRED, the character to split the @List string on
        ,@List                 varchar(8000)        --REQUIRED, the list to split apart
    )
    RETURNS
    @ParsedList table
    (
        ListValue varchar(500)
    )
    AS
    BEGIN
    
    /**
    Takes the given @List string and splits it apart based on the given @SplitOn character.
    A table is returned, one row per split item, with a column name "ListValue".
    This function workes for fixed or variable lenght items.
    Empty and null items will not be included in the results set.
    
    
    Returns a table, one row per item in the list, with a column name "ListValue"
    
    EXAMPLE:
    ----------
    SELECT * FROM dbo.FN_ListToTable(',','1,12,123,1234,54321,6,A,*,|||,,,,B')
    
        returns:
            ListValue  
            -----------
            1
            12
            123
            1234
            54321
            6
            A
            *
            |||
            B
    
            (10 row(s) affected)
    
    **/
    
    
    
    ----------------
    --SINGLE QUERY-- --this will not return empty rows
    ----------------
    INSERT INTO @ParsedList
            (ListValue)
        SELECT
            ListValue
            FROM (SELECT
                      LTRIM(RTRIM(SUBSTRING(List2, number+1, CHARINDEX(@SplitOn, List2, number+1)-number - 1))) AS ListValue
                      FROM (
                               SELECT @SplitOn + @List + @SplitOn AS List2
                           ) AS dt
                          INNER JOIN Numbers n ON n.Number < LEN(dt.List2)
                      WHERE SUBSTRING(List2, number, 1) = @SplitOn
                 ) dt2
            WHERE ListValue IS NOT NULL AND ListValue!=''
    
    
    
    RETURN
    
    END --Function FN_ListToTable
    

    you can use this function as a table in a join:

    SELECT
        Col1, COl2, Col3...
        FROM  YourTable
            INNER JOIN FN_ListToTable(',',@YourString) s ON  YourTable.ID = s.ListValue
    

    so for Linq, create a stored procedure:

    CREATE PROCEDURE YourProcedure
    (

     @param1  int
    ,@param2  varchar(8000) --csv list is here
    

    )
    as

    SELECT
        Col1, COl2, Col3...
        FROM YourTable
            INNER JOIN FN_ListToTable(',',@param2  ) s ON  YourTable.ID = s.ListValue
        WHERE Col1=@param1
    

    go

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.