Data Layer extension package efcachingprovider Summary

Source: Internet
Author: User

I recently learned efcachingprovider. This extension package can be used not only for the extension of entityframework, but also for all applications related to database connections.ProgramYou can use a similar solution for expansion. Make a small summary today to facilitate future review.

 

General description

For more information about what efcachingprovider is and how to use it, see this article in garden.Article: Entity Framework cache processing and log monitoring. I will mainly talk about the internalCodeImplementation principle.

The figure in the garden article shows the extended position of efcachingprovider:

That is to say, entityconnection does not directly use sqlconnection In The Middle Of sqlclient, but converts the command through efcachingprovider and then uses sqlclient for execution.

Solution Structure

Key Project explanation:
Efproviderwrappertoolkit: defines the sqlclient extension framework, including dbconnectionwrapper and dbcommandwrapper.
Efcachingprovider: Implements sqlclient extensions in the form of caching, including dbcachingconnection and dbcachingcommand.
Eftracingprovider: added the log monitoring function based on sqlclient.

 

How to expand

Although efcachingprovider is named, It is a cache extension package of entityframework. But it is actually directly extended on system. Data. Common. That is to say, this extension package can be used for any application dealing with databases. (A few modifications may be required .)

It uses the decoration mode and abstract factory and directly inherits the following core ADO. Net objects: dbconnection, dbcommand, dbcommanddefinition, dbproviderfactorybase, dbproviderservicesbase, and is named *** wrapper. The following are extensions of dbconnection:

The specific decoration code is in the static method dbconnectionwrapper. wrapconnection:

/// <Summary> /// wraps the connection. /// </Summary> /// <Param name = "connection"> the connection. </param> // <Param name = "wrapperproviderinvariantnames"> the wrapper provider invariant names. </param> // <returns> wrapped connection. </returns> internal static dbconnection wrapconnection (dbconnection connection, Params string [] wrapperproviderinvariantnames) {foreach (string invariantname in wrapperproviderinvariantnames) {dbproviderfactory factory = dbproviderfactories. getfactory (invariantname); var connectionwrapper = factory. createconnection (); dbconnectionwrapper wrapper = (dbconnectionwrapper) connectionwrapper; wrapper. wrappedconnection = connection; connection = connectionwrapper;} return connection ;}

Usage:

Dbconnectionwrapper. wrapconnection (storeconnection, "eftracingprovider", "efcachingprovider ")

 

Summary

Efcachingprovider is a decoration mode extension package in system. Data. Common. Therefore, it can also be applied to database application systems other than entityframework. At the same time, it supports other extensions based on the framework.

If your database access system requires functions such as caching and tracing, try using this extension package. :)

 

Related links:

Http://code.msdn.microsoft.com/EFProviderWrappers

Http://kb.cnblogs.com/page/72713/

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.