ABP combat Lesson 3: connect to the database through DbContext

Created a database entity classes later, the next step is the connection to the database processing, ABP DbContext framework creates a template for us, this template in the EntityFramework, called XXDbContext, XX is the name of your project:

 

 

Step one: Open XXDbContext, you will see there are a TODO comment, it is to tell you to define your own entity classes: IDbSet, so we have to be on all entities in a class definition generated to tell a IDBSet

 

 

 

 

 

Step Two: Once defined, we look at the big XXDbContext class has a constructor, the constructor is to call the constructor of the parent class, and pass a "Default" string, the "Default" is the connection to the database the key, the "Default" is defined in the Web.config file in the Web project, the program is actually read by: connectionString in the database connection string

 

 

 

The third step: the above: connectionString come from? Find VS --- --- tool to connect to the database, the pop-up dialog box, enter the server name ---- --- Select the database to test the connection, if the connection is successful, then click the Advanced tab, copy the following to connectionString this is the specific value of connectionString

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/hh8888-log/p/11891119.html