Find method:
// Find Method
// Used to search for a single object through the primary key.
// Advantage: Find will first be searched in the context cache. if it finds it, it will return directly to avoid database queries. Firstordefault always queries the database, regardless of whether the cache already exists.
Guid actionitemid = guid. newguid ();
Actionitem = context. actionitems. Find (actionitemid );
Include Method
// Include method (reference system. Data. entity namespace first)
// Used for one query, and all related objects are found at one time.
// Advantage: it can greatly reduce the number of database queries and greatly improve page performance.
Ienumerable <actionitem> actionitems = context. actionitems
. Include (item => item. Histories)
. Include (item => item. actionitemmembers)
. Where (item => item. assigneeid = This. User. Identity. Name );
// The following is the description of msdn's use of include.
// To include a single reference: Query. Include (E => E. level1reference ).
// To include a single collection: Query. Include (E => E. level1collection ).
// To include a reference and then a reference one level down: Query. Include (E => E. level1reference. level2reference ).
// To include a reference and then a collection one level down: Query. Include (E => E. level1reference. level2collection ).
// To include a collection and then a reference one level down: Query. Include (E => E. level1collection. Select (L1 => l1.level2reference )).
// To include a collection and then a collection one level down: Query. Include (E => E. level1collection. Select (L1 => l1.level2collection )).
// To include a collection, a reference, and a reference two levels down: Query. Include (E => E. level1collection. Select (L1 => l1.level2reference. level3reference )).
// To include a collection, a collection, and a reference two levels down: query. include (E => E. level1collection. select (L1 => l1.level2collection. select (L2 => l2.level3reference ))).
Entityfunctions class
// Entityfunctions class (first reference the system. Data. Objects namespace)
// For some queries not supported by LINQ to entity, the methods in entityfunctions are required.
Context. actionitems. Where (item => entityfunctions. truncatetime (item. createtime) = datetime. Today );