EF's Model First

=> Add Data Model

 

=> Entity Data Model Wizard (Select "Design Model EF empty")

 

=> After generating the project will add several files

 

=> New Entity

Create a User entity, the primary key for the Id

=> Right added scalar property

=> Right property, these fields may be set length, type, whether empty, etc.

=> Then create a sales order table. New association to associate the User and SalesOrder

=> After navigation related attributes automatically added

=> Right-click the add item code generation

=> Automatically generated code

// ------------------------------------------------ ------------------------------ 
// <Auto-generated> 
// this code generated from the template. 
// 
// manually change the file may cause unexpected behavior of the application. 
// If the code is regenerated, the cover manually change this file. 
// </ Auto-Generated> 
// ---------------------------------------- -------------------------------------- 

namespace MeKa.RoleSystem.Model 
{ 
    the using the System; 
    the using the System .Collections.Generic; 
    
    public partial class the SalesOrder 
    { 
        public int Id {GET; SET;} 
        public String the Content {GET; SET;} 
        public int the UserId {GET; SET;} 
    
        public {GET the User Virtual the User; SET;} 
    } 
}

=> DbContext, generated automatically inherits from class DataModelContainer DbContext, which can track changes entity 

=> Right-click the database generated from the model

  

=> Select a database to a new database connection or

=> Create database tables generated sql

=> Execute Sql

=> Added to the database to verify the success of

 

Guess you like

Origin www.cnblogs.com/berlinman/p/11520629.html
Recommended