Build a backend management system for ASP. Mvc4+ef5+easyui+unity2.x Injection (4)-Build project Solution Create EF DataBase frist mode

Source: Internet
Author: User

Before we proceed with this article, we may need to add some basic knowledge.

First of all, our system is based on interface programming, why should we use an excuse to program, in fact, this is the application of an Enterprise Application architecture Pattern

Repository (warehousing)

A mechanism for encapsulating storage, reading, and finding behavior, which simulates a collection of objects.

Supports the goal of complete separation and one-way dependency between the domain and the data mapping layer.

Interface programming

The main purpose is to separate the focus points so that the developers have their own roles

Code hold confidential, subcontracting development, without the need to give logical structure code, only need to give the interface file

Disadvantage: The design is difficult, than the traditional three-tier, single-class mode difficult, but the interface programmer wages are very high!

AOP (aspect-oriented programming)

In order to compensate for object-oriented defects, we will introduce aspect-oriented programming

Mainly used for logging, transaction processing, exception handling and so on.

The concept of such things is too vague, we have to go through a large system to recognize these conceptual models. I can not use the article to analyze the deep concept of this system in detail, we need everyone to practice and tacit in daily work, recommend a. NET design bookMicrosoft. NET Enterprise Application Architecture Design This book describes in detail interface programming, aspect-oriented programming

Through the solutions we need to build the project above.

Although the controller layer of MVC contains logic, it is not possible for a large system to include the business and database underlying, although the models Model folder is provided, and in the second I delete it, we extract this layer of the model layer, the design of any layer is good, Are derived from the three-tier design pattern, and this system is no exception. We are based on the interface programming of the warehousing mode, so we must have bll,ibll,dal,idal corresponding class library.

OK, now let's right-click our solution. Established separately

    • APP.BLL (Business layer)
    • APP.IBLL (Business layer Interface)
    • App.dal (data tier)
    • App.idal (data-tier interface)
    • App.models (model)
    • App.common (General class Library)
    • App.core (Core class library)

Figure:

Added: EF5.0 VS2012 flagship version is already integrated with the EF5.0 we put him under the App.models class library.

Right-----Add New Item

Enter name DB everyone name, here choose Empty model, we are model priority mode, not code frist mode to pay attention to. For the system, I think the model first has an advantage.

Expand DB.EDMX Delete DB.Context.tt and db.tt to correctly use the DB frist mode, see the DB.EDMX Properties window, change the code generation policy to the default value

We open SQL Server if you installed VS2012 I believe your database is not old, I am SQL Server2008 R2 version

Let's create a simple case table:

Create database DB creates a DB name

use DB
go CREATE TABLE [dbo].[SysSample](      [Id] [ varchar ](50)  NOT NULL ,      [ Name ] [ varchar ](50)  NULL ,      [Age] [ int NULL ,      [Bir] [datetime]  NULL ,      [Photo] [ varchar ](50)  NULL ,      [Note] [text]  NULL ,      [CreateTime] [datetime]  NULL ,   CONSTRAINT [PK__SysSampl__3214EC075AEE82B9]  PRIMARY KEY CLUSTERED (      [Id]  ASC ) WITH (PAD_INDEX  =  OFF , STATISTICS_NORECOMPUTE  =  OFF , IGNORE_DUP_KEY =  OFF , ALLOW_ROW_LOCKS  =  ON , ALLOW_PAGE_LOCKS  =  ON ON [ PRIMARY ] ON [ PRIMARY ] TEXTIMAGE_ON [ PRIMARY ] GO

Okay, now that we have the database and the table, we add the model mapping to the database, and here I'm talking about the EF principle, EF is an ORM framework that automatically persists objects in the program to a relational database by describing the mapping between objects and relational databases, which is easy to use, performance-intensive generic persistence support will enable you to focus more attention on business development, so you know what is a transaction, join us to remove 10 data from the database, I deleted 1, after a while delete 1, as long as I commit the transaction to the database to delete, otherwise it will be deleted memory database, So the pressure on the database is small, the memory pressure is big.

Create a new connection-----select Microsoft SQL Server


Set here, in 2012 "code Generation Policy" set "Default" mode, 2013 is set to "Old ObjectContext"

I believe you have seen the effect at this time, I may have written too detailed, the article is a bit messy.

If you're familiar with the three-tier architecture, you can now reference the relationship between projects.

Here is a reference process: follow this to make a reference, with a clearer picture of what we are injecting, which we are quoting now

App.admin-------------app.models,app.common,app.core,app.ibll,app.bll,app.dal,app.idal,system.data.entity

APP.BLL-----------App.models,app.ibll,app.dal,app.idal,system.data.entity

APP.BLL--------------app.ibll,system.data.entity

App.dal--------------app.idal,system.data.entity

App.idal--------------System.Data.Entity

Next we will use the interface programming we implement a deletion and modification of code, some bad code

Build a backend management system for ASP. Mvc4+ef5+easyui+unity2.x Injection (4)-Build project Solution Create EF DataBase frist mode

Related Article

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.