Entity Framework - Where Clause

前端 未结 3 967
南笙
南笙 2021-01-20 00:48

Let\'s say i have a table named User. When I use the Entity Framework to get the records i do like this:

var db = new Context();
var users = db.Users;
         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-20 01:36

    From here http://msdn.microsoft.com/en-us/library/cc853327.aspx

    When you create an ObjectQuery or LINQ query, the query may not be executed immediately. Query execution is deferred until the results are needed, such as during a foreach (C#) or For Each (Visual Basic) enumeration or when it is assigned to fill a List collection. Query execution begins immediately when you call the Execute method on an ObjectQuery or when you call a LINQ method that returns a singleton query, such as First or Any. For more information, see Object Queries and Query Execution (LINQ to Entities).

    So when your query has a WHERE clause it will just load the results filtered by the database with the where.

提交回复
热议问题