c#5.0 brings parallel programming.
{c#1.0 managed code →c#2.0 generic →c#3.0linq→c#4.0 Dynamic Language →c#5.0 asynchronous Programming}
With C # 5.0 after the. net4.5 out, their main push of the parallel technology has gradually become more and more hot, this heat has been sent to me here, as the storage uncle, I must also for their own storage of parallel transformation, this is the trend, hehe, today is mainly to my Irepository.core project to expand, that is, add some Corresponding parallel interface, and then let my parallel (asynchronous) warehousing to implement it, in fact,. NET EF this piece, implementation of asynchronous (parallel) very easy, in the c#5.0 because of the advent of the ASYNC/AWAIT keyword, which makes the implementation of asynchronous become easier, hehe, or that sentence, As a program writer in the. net domain, I feel happy!
IRepository becomes Irepositoryasync.
/// <summary> ///Asynchronous Operation///basic Data Manipulation Specifications///agnostic to ORM Architecture/// </summary> /// <typeparam name= "TEntity" ></typeparam> Public InterfaceIrepositoryasync<tentity>whereTEntity:class { /// <summary> ///sets the data context, which is typically injected by the schema method/// </summary> /// <param name= "Unitofwork" ></param> voidSetdbcontext (iunitofwork unitofwork); /// <summary> ///adding entities and committing to the data server/// </summary> /// <param name= "Item" >Item to add to Repository</param>Task Insert (TEntity item); /// <summary> ///remove entities and submit to data server///If the table has constraints, you need to delete the child table information first/// </summary> /// <param name= "Item" >Item to delete</param>Task Delete (TEntity item); /// <summary> ///modifying entities and committing to a data server/// </summary> /// <param name= "item" ></param>Task Update (TEntity item); /// <summary> ///gets the specified entity collection (deferred result set)///Get all elements of type {T} in Repository/// </summary> /// <returns>List of selected elements</returns>Iqueryable<tentity>Getmodel (); /// <summary> ///get entities based on primary key/// </summary> /// <param name= "id" ></param> /// <returns></returns>TEntity Find (params Object[] ID); }Iextensionrepository becomes Iextensionrepositoryasync.
/// <summary> ///Asynchronous Operation///Extended repository Operation specification/// </summary> Public InterfaceIextensionrepositoryasync<tentity>: Irepositoryasync<TEntity>, Iorderablerepository<TEntity>whereTEntity:class { /// <summary> ///Add Collection [Use this method when the number of collections is small, large collection uses Bulkinsert]/// </summary> /// <param name= "item" ></param>Task Insert (ienumerable<tentity>item); /// <summary> ///Modify Collection [Use this method when the number of collections is small, large collection using Bulkupdate]/// </summary> /// <param name= "item" ></param>Task Update (ienumerable<tentity>item); /// <summary> ///Delete Collection [with this method when the number of collections is small, large collections using bulk Delete]/// </summary> /// <param name= "item" ></param>Task Delete (ienumerable<tentity>item); /// <summary> ///gets the delay result set based on the specified lambda expression/// </summary> /// <param name= "predicate" ></param> /// <returns></returns>Iqueryable<tentity> Getmodel (expression<func<tentity,BOOL>>predicate); /// <summary> ///gets the first entity based on a specified lambda expression/// </summary> /// <param name= "predicate" ></param> /// <returns></returns>TEntity Find (expression<func<tentity,BOOL>>predicate); /// <summary> ///Bulk Add, add before you can remove the self-increment property, default does not remove/// </summary> /// <param name= "item" ></param> /// <param name= "isremoveidentity" ></param>Task Bulkinsert (ienumerable<tentity> item,BOOLisremoveidentity); /// <summary> ///Bulk Add/// </summary> /// <param name= "item" ></param>Task Bulkinsert (ienumerable<tentity>item); /// <summary> ///Batch Update/// </summary> /// <param name= "item" ></param>Task bulkupdate (ienumerable<tentity> item,params string[] fieldparams); /// <summary> ///Bulk Delete/// </summary> /// <param name= "item" ></param>Task Bulkdelete (ienumerable<tentity>item); /// <summary> ///after saving/// </summary> EventAction<savedeventargs>aftersaved; /// <summary> ///before saving/// </summary> EventAction<savedeventargs>beforesaved; }Ispecificationrepository becomes Ispecificationrepositoryasync.
/// <summary> ///EF Underlying architecture, warehousing interface for protocol functions/// </summary> /// <typeparam name= "TEntity" ></typeparam> Public InterfaceIspecificationrepositoryasync<tentity>: Iextensionrepositoryasync<TEntity>whereTEntity:class { /// <summary> ///get the delay result set according to the specified protocol/// </summary> /// <param name= "Specification" ></param> /// <returns></returns>Iqueryable<tentity> Getmodel (ispecification<tentity>specification); /// <summary> ///the first entity is obtained according to the specified statute/// </summary> /// <param name= "Specification" ></param> /// <returns></returns>TEntity Find (ispecification<tentity>specification); /// <summary> ///with the sorting function, the result set is obtained according to the specified protocol ./// </summary> /// <param name= "by" ></param> /// <param name= "Specification" ></param> /// <returns></returns>Iqueryable<tentity> Getmodel (action<iorderable<tentity>>, ispecification<tentity>specification); }
As you can see, the storage Uncle's asynchronous interface is the end of async, which is also in compliance with Microsoft's specifications, such as the synchronous ToList () method is changed to asynchronous after the Tolistasync (), and the account is not modified on the original interface, but the expansion of the asynchronous interface, The method name does not change and feels like this to the program developer
To be more friendly, more acceptable, that is, our cud operation or (Insert,update,delete), just on the interface to distinguish, you use the IRepository interface to declare the instance, generated is synchronous operation, An instance that uses the Irepositoryasync declaration is an asynchronous implementation of the operation.
The transformation of EF asynchronous Transformation-first time warehousing interface