Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use EntityFramework.Extended to extend EF

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

How to use EntityFramework.Extended to extend EF, for this problem, this article describes the corresponding analysis and solution in detail, hoping to help more small partners who want to solve this problem find a simpler and easier way.

preface

Today we are going to talk about EntityFramework.Extended

First of all, let's popularize what EntityFramework.Extended is, as follows:

This is a class library that extends Entity Framework.

Full support for EF 5.0/6.0+,

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

Last updated on 07/10/2015

This library supports batch updates and deletions. Query results cache and audit logs.

This extension generates only one sql statement per batch manipulation, rather than N sql statements for batch N data as the native approach provided by EntityFramework

Environment and technology adopted

System:WIN7

Database:SQL Server2008

Related technologies:MVC5+EF6.1.3+EntityFramework.Extended6.0

Chapter 1: Batch Database Manipulation

Batch deletion:

//Remember to refer to using EntityFramework.Extensions;//Either way,Context is your EF context object.context.LogData.Delete(a => a.EntityKey == "aa");context.LogData.Where(a => a.EntityKey == "aa").Delete();

Batch update:

//data int is the number of rows modified data =context.LogData.Where(a=>a.EntityKey=="aa").Update(b=> new LogData { EntityName = "ss" });//The second way, this is for DbSet, has been marked obsolete var data = context.LogData.Update(a => a.EntityKey == "aa",b=> new LogData { EntityName = "ss" });

Batch increase:

//This has nothing to do with Extended.. It's just a simple example of how the EF itself comes with, and how God ignores it. int data= context.LogData.AddRange(new List());

Chapter 2: Batch Query Database

Here's how it works:

E text original text:

Future queries work by creating the appropriate IFutureQuery object that keeps the IQuerable. The IFutureQuery object is then stored in IFutureContext.FutureQueries list. Then, when one of the IFutureQuery objects is enumerated, it calls back to IFutureContext.ExecuteFutureQueries() via the LoadAction delegate. ExecuteFutureQueries builds a batch query from all the stored IFutureQuery objects. Finally, all the IFutureQuery objects are updated with the results from the query.

The Spicy Chicken of Xiao Bian

Future will create its own custom IFutureQuery object based on IQueryable, and then add it to the IFutureContext.FutureQueries query queue. When an object in the queue calls LoadAction, it will execute IFutureContext.ExecuteFutureQueries() method, ExecuteFutureQueries will build an IFutureQuery for batch query, and finally update all IFutureQuery query query results (that is, queries).

Chapter 3:EF's Data Audit Log

Data audit logs:

The audit concept is to monitor all entity operations (add, delete, modify).

This is the information he tracks, and we can easily store it in a database or in your log store (text,XML, cache)--whatever you want.

Let's start with the usage:

First we can configure it at the application's entry ( Application_Start)(I'll use the MVC Web application as an example here):

The configuration here can be omitted, and the default is also OK.

About how to use EntityFramework.Extended to expand the EF questions to share here, I hope the above content can be of some help to everyone, if you still have a lot of doubts, you can pay attention to the industry information channel to learn more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report