Reverse generation of EF power tool Code Generator

Source: Internet
Author: User

This tool provides the following functions:

1) generate code first poco class, dbcontext class, and corresponding mapping class according to the existing database structure.

2) view the Entity Data Model (edmx) corresponding to the POCO class in designer or XML mode ).

3) view the DDL corresponding to the Entity Data Model.

4) generate EF generated view to improve EF performance.

Together. Of course, please download and install this tool first. You must install it before installation.Ef4.1.

First, create two tables (Parent and Child) on the database. There is a one-to-many relationship.

First, create two tables (Parent and Child) on the database. There is a one-to-many relationship.

 

Create a C # project and right-click the project name. Choose Entity Framework> reverse engineer code first in the pop-up menu.

 

Then select the corresponding database connection:

 

Then, a magic scene happened. The gadgets help us generate many classes:

 

The corresponding poco class, dbcontext class, and mapping fluent APIs are automatically generated, which is too easy. This greatly facilitates us to learn the fluent API related to EF 4.1.

 public class Parent{public Parent(){this.Children = new List<Child>();}public int ParentID { get; set; }public string Name { get; set; }public virtual ICollection<Child> Children { get; set; }} public class EFToolContext : DbContext{static EFToolContext(){Database.SetInitializer<EFToolContext>(null);}public DbSet<Child> Children { get; set; }public DbSet<Parent> Parents { get; set; }protected override void OnModelCreating(DbModelBuilder modelBuilder){modelBuilder.Conventions.Remove<IncludeMetadataConvention>();modelBuilder.Configurations.Add(new ChildMap());modelBuilder.Configurations.Add(new ParentMap());}}<!-- .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } --> public class ParentMap : EntityTypeConfiguration<Parent>{public ParentMap(){// Primary Keythis.HasKey(t => t.ParentID);// Propertiesthis.Property(t => t.ParentID).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);this.Property(t => t.Name).IsRequired().HasMaxLength(50);// Table & Column Mappingsthis.ToTable("Parent");this.Property(t => t.ParentID).HasColumnName("ParentID");this.Property(t => t.Name).HasColumnName("Name");}} 

 

After having these classes, we can also view the corresponding Entity Data Model and corresponding DDL through the gadgets. Even better, the gadgets can also produce code for EF generated view for us to improve our performance when using EF and code first.

 

 

It is worth mentioning that the Entity Data Model, Entity Data Model XML, and Entity Data Model DDL are both read-only and are generated in C: \ Users \ [username] \ appdata \ Local \ temp \ folder.

 

After optimize Entity Data Model is selected, the gadgets will add a. View. CS file for your project. The code for generated views will be included in the interim.

Reverse generation of EF power tool Code Generator

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.