What are the different Entity Framework7? What is the level of development now?

Source: Internet
Author: User

Entity Framework7 First, Entity Framework7 introduction

Entity Framework7 abbreviation EF7, is the newest in which Microsoft is developing. NET application in the data access technology. It is a lightweight and extensible Entity Framework version that enables new platforms and new data stores. The following apps: Windows Phone, Windows Store, ASP. NET 5 and traditional desktop applications can now be leveraged by the Entity Framework. In addition to supporting relational databases, EF7 supports such as Azure tables and redis non-relational data stores.

From the above we can see the following several points:

1, EF7, as in previous versions, is still a data access technology;

2, EF7 is a lightweight and extensible Entity Framework; The lighter is the earlier version, the previous version because of the numerous legacy issues (such as contextual objects have ObjectContext and dbcontext two versions) and previous design problems, has been very complex and large, It contains the complexity of use. EF7 was a major change, and Microsoft decided to refactor it from the ground up;

3, EF7 support non-relational data storage;

Ii. What is the difference between Entity Framework7

  1. What is the same as the previous version?

When using it, the top-level interface is basically the same as the previous version,

A, you can still inherit the DbContext context object, and still have the dbset<tentity> attribute in the context;

b, you can still write queries using LINQ on the Dbset attribute;

C, you can still use the add and remove methods on the Dbset property;

D, you can still use the Dbcontext.changetracker and Dbcontext.database properties to access object tracking and invoke database-related APIs;

For example, the following code is spelled in ef6.x and EF7

1 using(vardb =NewBloggingcontext ())2 {3Db. Blogs.add (NewBlog {URL ="blogs.msdn.com/adonet" });4 db. SaveChanges ();5  6  varBlogs = fromBinchDb. Blogs.include (b =b.posts)7               byB.name8              Selectb;9 Ten  foreach(varBloginchblogs) One  { A Console.WriteLine (blog. Name); -   foreach(varPostinchBlog. Posts) -   { theConsole.WriteLine (" -"+Post. Title); -   } -  } -}

  

  2. What are the changes?

A, new features

A . Support batch update of relational data. What do you mean you don't have to elaborate, before this, a lot of people sprayed the dung ef, that is, his update efficiency is too low, if you want to implement batch update, especially when inserting, need to use SQL statement or third-party tool class. Believe that this is the function that many people expect;

B, support unique constraints. it allows you to identify an additional key within the entity in addition to the primary key and use them as a foreign key.

B, Behavior (Behavior) change

In EF6 and upfront versions, the top-level API has a lot of non-intuitive behavior, although EF7 as much as possible to keep the top-level API the same, but still remove some restrictions and add some of the behavior we expect. What do you mean? This sounds a little confusing, for example, the previous query, although LINQ brings us a lot of convenience, but the limit of Ah, the entire LINQ query is translated into a separate SQL query, LINQ query can only contain the EF can be translated into SQL statements or methods; Sometimes it generates complex, inefficient, and not the SQL statements we want. EF7 change this situation, you can return a multi-result set, and the SQL evaluation work is not done on the database side, changing to the client. This gives you a lot of flexibility in generating SQL. If it's still a little dizzy, it's okay, just have an impression.

C, become more simple, flexible

Just use an example to illustrate it. We want to get the metadata from EF to which table the blog entity is mapped to in the database. Before that, our code would be like this:

1 using(varContext =NewBloggingcontext ())2 {3  varmetadata =((iobjectcontextadapter) context). Objectcontext.metadataworkspace;4  varObjectItemCollection =((objectitemcollection) metadata. Getitemcollection (Dataspace.ospace));5  6  varEntityType =metadata7. Getitems<entitytype>(Dataspace.ospace)8. Single (e = Objectitemcollection.getclrtype (e) = =typeof(Blog));9  Ten  varEntitySet =metadata One. Getitems<entitycontainer>(Dataspace.cspace). Single () A   . EntitySets -. Single (s = = S.elementtype.name = =entitytype.name); -   the  varmapping = metadata. Getitems<entitycontainermapping>(Dataspace.csspace). Single () -   . Entitysetmappings -. Single (s = = S.entityset = =entitySet); -   +  varTable =Mapping -   . Entitytypemappings.single () +   . Fragments.single () A   . StoreEntitySet; at   -  varTableName = (string) table. metadataproperties["Table"]. Value??table. Name; -}

In EF7 the code would be like this:

1 using (varnew  bloggingcontext ()) 2 {3  var tableName = db. Model.getentitytype (typeof(Blog)). Relational (). Table; 4

   D, removed some features

A, each type maps multiple entity sets (MEST). This feature, estimated to use few people, it is because the use of fewer people, so it was removed. What does it mean? is a database of multiple tables in a type, for example: Table product and Retriedproduct are mapped to the product class. If you still have this requirement, using inheritance is a better choice.

b, very complex type mappings. In ef6.x, TPH,TPT and TPC may be combined in an inheritance map. EF7 no longer supports this complex mapping, which requires that your CLR type be kept as much as possible with the table structure. As for why, I am the same many people have not yet figured out what is TPH,TPT,TPC, that is even less flexible operation, which is leading to the ef6.x MetadataWorkspace complex one of the main original.

      c. Get rid of the EDMX modeling . This may disappoint a lot of people, because it has brought us a wonderful memory. But it has a lot of shortcomings, compare some complex requirements, not adapt to the DDD layered design, does not conform to the current popular Poco and so on. The main thing is, there is better choice code-based modelling, this is what we often say code-first. Perhaps you will have doubts, how Code-first and edmx is a lateral concept, it is not with db-first, Model-first lateral? Yes, it's an edmx-like, more detailed explanation. Check out my other blog, code first is a bad name, and we're wrong about code first these years! Are you shocked?

D, ObjectContext API. It grew up with EF and was dbcontext behind the scenes at EF4.1. But DbContext is just its appearance pattern, and the bottom is still used for it. Sometimes when we need to use some advanced features, we have to find ways to get it out. Removing it does not mean that some of its previous functions are useless. EF7 rewritten the underlying, the API that must be used before ObjectContext to be included in the DbContext, and make the call clearer and simpler.

E, lazy loading. This function believes that everyone is not unfamiliar, it has been regarded as a major feature of EF, but now, it will be removed from the EF7. I'm not sure if the final version of Microsoft will bring it back, because there's a big debate. Whether it's our developers, or the development team at EF. I personally support the removal. One, not all applications require lazy loading; second, a lot of EF users do not have a deep understanding of it, often people ask, why there will be "unable to complete the operation, because DbContext has released" such a problem. This shows that this function is rather confusing to a user.

These changes are not final, and may change in the words of the text. Of course, it is not possible to list all the points of change, after all, EF7 is still in the development process. In short, it is a revolutionary version, so that some people are arguing should call him EF7, or EF1.

E, the support of non-relational database, the beginning of the article has been mentioned, there is not much to say;

F, the official support Sqlite; This estimate is good for many developers, at least, I've had a lot of time to use LINQ to SQLite, and I was born for him in the blog park. Linq to SQLite 1122

Iv. Development Plan of EF7

I believe that many people, like me, began to look forward to EF7 's release last year. More than a year long wait, but it has not come out, in the end when it? Microsoft's plan is 2016, so we have to wait patiently. However, the good news is that it is open source, the latest source code on GitHub, if you want to learn more details, you can go to the following address (Https://github.com/aspnet/EntityFramework) to clone or download the source. The following is the EF's Development plan table

Say so much today, thank you for reading! If there is any inappropriate place, or the text did not mention, please leave a message, thank you! If you feel good, please move the mouse, click the recommended bar ~

  

Entity Framework Exchange QQ Group: 458326058, welcome interested friends to join the exchange

Thank you for your continued attention, my blog address: http://www.cnblogs.com/VolcanoCloud/

What are the different Entity Framework7? What is the level of development now?

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.