From oxite, we can see the multi-layer architecture of applications using ADO. NET Entity Framework.

Source: Internet
Author: User

I often see people asking how to layer a project that uses ADO. NET Entity Framework or LINQ to SQL. EF or linq2sql generates an entity class by themselves. Since entity classes run through the entire project, if the automatically generated entity class is used as part of the entire project entity class, most classes in the project will be dependent on the data access layer. When the database structure changes or the data access layer changes, the entire project may change accordingly. This design is not very good. However, most of the samples provided by Ms previously use the automatically generated object class as the entity class of the entire project. It may be because the previous sample is relatively small. I also thought about writing a conversion class to convert between dbml and EDM and the object class, but it is not very good. There is also a blog about the layered architecture in ADO. Net EF.
A few days ago, I saw the oxite message (http://news.cnblogs.com/n/43866/), and then I looked at his architecture. It defines object class interfaces in the project. Bll and UI use this interface for programming. Dal uses an object class used in the data access layer to inherit the object class interfaces in these projects. Take the user entity class as an example to define an iuser interface under oxite. Data. Bll and UI both use this interface as an object class. In Dal (oxite. linqtosqldataprovider), you can find a partialclasses. CS file, which implements various object class interfaces. Here we can find the partial class oxite_user: iuser, which implements the iuser interface, and it is a partial class, and the other half is in the dbml file. Let's look at the attributes of partial class oxite_user: iuser.Code For example, public guid ID, which only transmits the value assigned to the ID to the userid, and then obtains the value of the userid, which is defined in dbml (EDM, therefore, you can use LINQ to SQL (LINQ to entity) to operate on it and reflect it to the database. The ID implements the ID attribute in the interface, so that the entity class and dbml (EDM) and other projects only depend on the data access layer interface and object interface instead of the data access layer. In addition, each class in the Dal has the savechanges method, calling this method after all associated update, insert, and delete operations are completed can reduce the number of times the database is opened and closed, and increase the efficiency. Although oxite uses LINQ to SQL, you can refer to this method for projects that use ADO. NET Entity Framework.

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.