Export to Entity Framework Code First

Export to Entity Framework C# Code First Models

It would be cool if you could export your diagram from this tool to simple C# Code First classes.

For example, I have a simple database with 2 tables:

Table User {
  Id integer [primary key]
  Username varchar
  Role varchar
  DateCreated timestamp
  DealerId integer
}

Table Dealer {
  Id integer [primary key]
}

Ref: Users.DealerId > Dealers.Id

That would export to something similar to:

User.cs

public class User 
{
[key]
public int Id {get; set;}
public string {get; set;}
public string Role {get; set;}
public datetime DateCreated {get; set;}
public int DealerId {get; set;}
public Dealer Dealer {get; set;}
}

Dealer.cs

public class Dealer
{
[key]
public int Id {get; set;}
}

This would save a lot of time for C# developers, you can meet with the business, analyze and build the diagram in dbdiagram.io in the meeting while they explain the requirements. Then when you start coding you simply convert the diagram to C# classes and Entity Framework code first will build the database for you :slight_smile:

Thank you for the feedback! We will try to support this in the future!

However, in the meantime, you can use ChatGPT as a workaround for the conversion! Here is our tutorial post:

Hope this helps!

Yea, I tried Bing AI Chat (which is Chat GPT 4) to do this before posting, but it failed. I also looked for tools online but I didn’t find any.
So this afternoon I wrote my own C# DotNet Core 7 Windows Desktop App to do it!

djorchard/GenerateEFModels: Paste DBML from dbdiagram.io and generate C# EF Models and Data Context (github.com)

Its not perfect, It doesn’t do indexes or relationships, but its good enough for my basic needs.

You paste DBML in, and it will create all the C# Models:

Yeah, we have to admit that the results of Bing AI Chat are strange for these questions. Perhaps it has been tailored specifically for search purposes. However, we tested your example with the ChatGPT. The answer is quite satisfactory:

We hope this information is useful. Thanks.