Entityframework is better than linqtosql

Source: Internet
Author: User

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 );

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.