Entity Framework - Where Clause

前端 未结 3 969
南笙
南笙 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:23

    Entity Framework will translate such a query into a "Store Expression." That is, it will generate a database query -- assuming your data storage is a database -- that will be somewhat similar to the query you included in your question. It very well may name the columns, however, and there are likely to be some other differences.

    0 讨论(0)
  • 2021-01-20 01:25

    The Sql submitted to your database will contain your where clause. You can use SQL Server Profiler to watch as queries are submitted to your DB.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题