none
Parameters in Dynamic Linq RRS feed

  • Question

  • Hi there:

    How do I use parameters in dynamic linq?.

    I want to code something like:

    var query = db.Customers.Where("nombre = @1").Select("it");

    How do I build the list of parameters @1, @2, etc..?

    Rafael
    Believe you can do it, and you will!!
    Wednesday, October 28, 2009 1:42 PM

Answers

  • You can pass them in as params (one by one), or as an object array (which is more useful if number of params vary and is determined at runtime).

    object[] paramValues = new object[] { "Jose", "Cuervo" };
    var query = db.Customers.Where("nombre = @0 && apellido = @1", paramValues).Select("it");


    Kristofer - Huagati Systems Co., Ltd.
    Cool tools for Linq-to-SQL and Entity Framework:
    huagati.com/dbmltools (add-in with new features for Visual Studio 2008's L2S and EF designers)
    huagati.com/L2SProfiler (Query profiler for Linq-to-SQL and LLBLGen Pro)
    • Marked as answer by RalphDev Wednesday, October 28, 2009 2:02 PM
    Wednesday, October 28, 2009 1:49 PM
    Answerer