EF thread unique docking with Dbsession interface

Source: Internet
Author: User

The EF is (Entity Framework) unique to the DbContext startup thread for the database context, so that there is no dirty data to process the data, and you can use the factory to co-create DbContext

Dbsession Instance Code:

public class Dbsession:idbsession
{

Private DbContext Db
{
Get
{
Create thread the only ef,dbcontextfactory is the EF factory
return Dbcontextfactory.createunitycontext ();
}

}

dbcontextfactory Code : function to determine whether the data context exists is unique to the data context

DbContext DbContext = (DbContext) callcontext.getdata ("DbContext");

if (dbcontext==null)
{
DbConText = new Oaentities ();//oaentities () is the data context Model1. Context.cs in the
//. SetData ("DbConText", dbConText); store data
Callcontext.setdata ("DbConText", DbConText);
}

return dbConText;

How to implement multi-table operations to save data one time, in order to avoid using the data link pool multiple link database

Unified extraction in Dbsession painting

Db.savechanges () can be solved in the installation and interface

So the EF thread is the only one that's docked to the Dbsession interface.

EF thread unique docking with Dbsession interface

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.