Some key points of the DbContext API

Source: Internet
Author: User

* Some key points of the DbContext API
*
* db. Categories.find ()-Finds an entity by passing a primary key value as a parameter, and a composite primary key passes multiple parameters
* db. Categories.add ()-Adds a new entity to the context
* db. Categories.attach ()-Adds an existing entity to the context
* db. Entry (entity). state = System.Data.EntityState.Modified-Modify Entity status
* db. Categories.asnotracking ()-an entity that is not tracked by the Context through NoTracking, and whose state is Detached state. It can be used only when data is obtained, which helps to improve efficiency.
* Property related operation, when the property changes, will automatically monitor the entity state, that is ismodified = True
* db. Entry (product). Property (P = p.name). CurrentValue
* db. Entry (product). Property ("Name"). CurrentValue
* Method of direct loading (Eager loading)
* db. Categories.include (P = p.products.first ())
* db. Categories.include (p = p.products)
* db. Entry (product). Reference (p = p.category). Load ()
* Using SQL
* db. Categories.sqlquery ("SELECT * from Categories"). ToList ()//entities in the case
* db. Database.sqlquery<string> ("Select Name from Categories"). ToList (); Non-entity situation
* db. Database.executesqlcommand (SQL); Execute SQL directly

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.