none
Compiled query with passing array issues RRS feed

  • Question

  • Hello All,

    I am working with compiled query with one of my project. I wanted to pass array type parameter into Compiled Query. As everyone knows that it is not possible to pass Array type parameter into Compiled Query, I have checked that when few of the below options are applied then at that time Compiled query works fine with Array type parameter.

    Can anyone one explain me what is the reason behind it?

     private Func<int[],IQueryable<Product>> _getProducts = CompiledQuery.Compile((Entities _entities,int[] productsids) => (
                
                    from p in _entities.Products
                    where productsids.Contains(p.ProductID)
                    select p;
                ));
    
            public IQueryable<Product> GetProducts(int[] productsids)
            {
                var res1 = _getProducts(productsids); // Not Working
    
                var res2 = _getProducts(productsids).ToList(); // Not Working
    
                var res3 = _getProducts(productsids).Count(); // Working
    
                var res4 = _getProducts(productsids).Where(p => p.ProductName == "test product").ToList(); // Working
    
                var res5 = _getProducts(productsids).OrderBy(p => p.ProductName).ToList(); // Working
            }

    In above code same compiled query is working with case marked with code comment " // Working" and same compiled query is not working with code comment " // Not working".

    Please explain me how some of cases are working and some of not working.

    Thanks in advance,

    Dharmesh Solanki

    Thursday, January 3, 2013 7:08 AM