Dynamic Where Clause over relational tables with LINQ to SQL

前端 未结 4 1523
既然无缘
既然无缘 2021-01-05 11:37

I need help for a dynamic where clause over relational tables (one to many) in LinqToSql.

User select conditions from page. (there is 4 input that u

4条回答
  •  一整个雨季
    2021-01-05 11:48

    Check out ScottGu's blog on the dynamic linq library. I think it will help.

    Here is an example of a query that hits both the customers and orders table:

        var query =
        db.Customers.
        Where("City = @0 and Orders.Count >= @1", "London", 10).
        OrderBy("CompanyName").
        Select("new(CompanyName as Name, Phone)");
        

    The query above came from the C# samples for Visual Studio. Download and look in the \LinqSamples\DynamicQuery folder and you will find more examples.

提交回复
热议问题