Entity Framework Extended Library

Source: Internet
Author: User

Expanded the functional class library of the Entity Framework.

https://github.com/loresoft/EntityFramework.Extended

1 Batch Update/delete

1) Delete

// Delete all users where FirstName matches " FirstName ");

2) Update

//Update All Tasks with the status of 1 to status of 2context. Tasks.update (t= = T.statusid = =1, T2=NewTask {Statusid =2});//example of using a IQueryable as the filter for the updatevarUsers = context. Users.where (U = u.firstname = ="FirstName"); context. Users.update (Users, U=NewUser {FirstName ="Newfirstname"});

2 Query Result Cache
Save the query results, using the extension method Fromcache is located in EntityFramework. Namespace extensions. The following is a sample cache Query result. from the build LINQ query you will then append the Fromcache extension.

1) Default settings

// Query   is cached using the default settings//query cache is to use the defaults setting var tasks = db. Tasks    null)    . Fromcache (); // Query result is now cached seconds//cache query results for 300 seconds
var tasks = db. Tasks    null)    . Fromcache (cachepolicy.withdurationexpiration (timespan.fromseconds));

2) Tag Cache

The query results cache also supports tag caching so that you can expire public cache entries by calling expired cache tokens.

//Cache assigned tasks setting up caching
vartasks =db. Tasks. Where (t= = T.assignedid = = myUserID && T.completedate = =NULL) . Fromcache (Tags:New[] {"Task","assigned-task-"+myUserID});//Some update happened to task, expire task tag if this changes. Expired Cache FlagCacheManager.Current.Expire ("Task");

CacheManager support provider using memorycache stores cache entries. implements a custom provider, implements icacheprovider . The custom provider will need to be registered with the locator parser.

// Replace cache provider with Memcached provider   replacement buffer new Memcachedprovider ());

Default Cache Policy

When no cachepolicy are set, the Cachepolicy.default is used. You can set the values of Cachepolicy.default on application startup to the Default settings.

When there is noCachePolicySettings, using the defaultCachepolicy.default。you can set the cachepolicy.default value. Defaults to the default settings when the application starts.

3 Checking Logs

Can capture changes to an entity at any time when it is committed to the database. The check log captures only the changed entities, capturing only the attributes of those entities that were changed. the value before and after the record. in this information Auditlogger.lastaudit is held and there is an easy way to put the check log as XML for easy storage of the ToXml () method.

The auditlog can customized via attributes on the entities or via a Fluent Configuration API.

Check logs can be configured through the fluent API through custom entities or attributes.

//Config audit when your application was starting up ... When your application starts, configure the check logvarAuditconfiguration =auditconfiguration.default;auditconfiguration.includerelationships=true; Auditconfiguration.loadrelationships=true; auditconfiguration.defaultauditable=true;//Customize the audit for Task entity custom Check log entityAuditconfiguration.isauditable<task>()    . notaudited (t=t.taskextended). Formatwith (t= T.status, V =Formatstatus (v));//Set the display member when status was a foreign key when the state foreign key is set to show componentAuditconfiguration.isauditable<status>()    . DisplayMember (t= T.name);

Create a check log

var New Trackercontext (); var audit = db. Beginaudit ();
// Make some updates ... Some code db. SaveChanges (); var log = audit. Lastlog;


Just with Google Translate ha. I just pasted it. If there is a translation error in place. Please forgive me.

Entity Framework Extended Library

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.