Using IQueryable
Using (new centastaffentities ()) { iqueryable<staff> queryablestaffs = db. Staff.asqueryable (). (P=>p.staffid). Skip (3). Take (3foreach (in queryablestaffs) {Console.WriteLine (item. Cnname); } }
Using IEnumerable
using (varnew centastaffentities ()) { IEnumerable<Staff> enumerablestaffs = db. Staff.asenumerable (). (p = p.staffid). Skip (3). Take (3); foreach (var in enumerablestaffs) { Console.WriteLine (item. cnname); } }
the difference between the IQueryable interface and the Ienumberable interface: ienumerable<t> generic classes before calling their own extension methods such as Skip and take, the data is already loaded in local memory, and Iqueryable<t> is the skip These method expressions are translated into T-SQL statements before sending commands to the SQL Server, which does not load all the data into memory for conditional filtering.
Reference: http://www.cnblogs.com/ambon/articles/4766924.html
Include (), the two tables must contain foreign key relationships, just specify the class property name corresponding to the key name, and you do not need to specify the result field (that is, all mappings). By default, when a table is searched, the foreign key table is not queried, and the database query is not read until it is actually used, and if Include () is used, the specified foreign key table information is read when the table is read.
using (varnew testentities ()) { IEnumerable<Student> enumerablestaffs = db. Student; foreach (var in enumerablestaffs) { // gets Console.WriteLine (item) every time. class.name); } }
Include
using (varnew testentities ()) { // preload associated table must have primary foreign key relationship ienumerable<student> enumerablestaffs = db. Student.include ("Class"); // query only once foreach (var in enumerablestaffs) { Console.WriteLine (item. class.name); } }
Left Join
EntityFramework ienumerable,iqueryable, Include