AddOrUpdate - use array as parameter

8

I'm running tests with the Entity Framework and I had a problem putting a array as a parameter.

  • Is this behavior normal?

  • If yes, what name?

  • It works

    List<Product> product = new List<Product>()
    var p = product.ToArray();
    db.Product.AddOrUpdate(x => x.Id, p);
    

    Does not work

    List<Product> product = new List<Product>()
    db.Product.AddOrUpdate(x => x.Id, product.ToArray());
    
        
    asked by anonymous 04.11.2015 / 15:32

    1 answer

    1

    This is because LINQ to Entities requires that the entire LINQ expression be translated to a server query and therefore you can not call a method from outside, in your case linq does not rearrange the data within your methods, that is, you can not convert your product to array product.ToArray() within method AddOrUpdate this method expects an array and not an object that calls the ToArray() method and returns an array.

    For this to work, you'll have to restructure your query expression in an expression that Entity Framework can handle .

        
    30.09.2016 / 19:28