Entity Framework Power Tools is a tool that is provided by the EntityFramework development team to generate a fluent version of code first from an existing database.
Roughly speaking, this tool has several features:
1) According to the existing database structure, generate code First POCO class, DbContext class, and corresponding mapping class.
2) View the Entity Data Model (EDMX) for Poco class in either Designer or XML mode.
3) View the DDL corresponding to the entity Data model.
4) Generate EF Generated view to improve EF performance.
Entity Framework Power Tools Installation
1. vs-Tools-Extension Manager-search: Entity Framework Power tools-then install
2. After the installation is complete, then restart VS
Right-click on the item and in the popup menu you will see a menu item with an Entity Framework added with a reverse Enginner Code first. Click to select a Data Connection window, and after establishing the data connection it will automatically generate the entity classes and corresponding mapping classes (placed in the mapping folder) mapped by all the data tables, and also automatically generate the DbContext class. Use these generated classes instead of the entity classes and context that you created directly through EF, powerful.
3. Part of the code generated by Entity Framework Power Tools
Model News
Using system;using system.collections.generic;namespace web.models{public partial class News {public int ID {get; set;} public string Title {get, set;} public string Cons {get, set;} public int counts {get; set;} public Sy Stem. DateTime times {get; set; }}}
Model Admin
Using system;using system.collections.generic;namespace web.models{public partial class Admin {public int ID {get; set;} public string Username {get, set;} public string Password {get; set;} public nullable<system.datetime> logintimes {get; set; }}}
DbContext
Using system.data.entity;using system.data.entity.infrastructure;using web.models.mapping;namespace web.models{public partial class Mvc_ceshi1context:dbcontext { static Mvc_ceshi1context () { Database.setinitializer<mvc_ceshi1context> (null);} public Mvc_ceshi1context (): Base ("Name=mvc_ Ceshi1context ") {} public dbset<admin> Admins {get, set;} public dbset<news> News {get; set ; } protected override void onmodelcreating (Dbmodelbuilder modelBuilder) {MODELBUILDER.CONFIGURATIONS.ADD (new Adminmap ()); MODELBUILDER.CONFIGURATIONS.ADD (New newsmap ()); }}}
Web. config also generates a link string
4, new Class library considerations
1. If you are creating a new class library, you must first refer to entity Framework.dll, otherwise the exception
2. Link to the database does not set the "Security connection" in the "Advanced Settings", the exception
Exception Graph (parameter error. (Exception from hresult:0x80070057 (E_INVALIDARG))):
msdn:https://msdn.microsoft.com/zh-cn/data/jj593170
Entity Framework Power Tools installation and use