When working with Entity Framework Core, adding a new entity usually involves several repetitive steps.

For example:

  1. Create the entity class.

  2. Add a primary key.

  3. Register the entity as a DbSet.

  4. Create an EF Core migration.

  5. Apply the migration to the database.

These steps are straightforward, but during rapid development they become repetitive.

That's why I built EFX, a small .NET global tool that combines this workflow into a single command.

The command

efx new Product

The tool creates the entity and adds the corresponding DbSet to the DbContext.

It then executes:

dotnet ef migrations add AddProduct
dotnet ef database update

The goal is not to hide EF Core. The goal is simply to automate the repetitive parts of the workflow.

Example

The generated entity looks like:

public class Product
{
    public int Id { get; set; }
}

And the DbContext receives:

public DbSet<Product> Products => Set<Product>();

After that, the migration is created and the database is updated.

Why EFX?

I originally built it because I was repeatedly performing the same sequence while prototyping.

When the schema changes frequently, small bits of automation can make the development loop much faster.

EFX is still a prototype, so I'm interested in feedback from other .NET and EF Core developers.

What would you add to it?

What problems do you think this approach might run into in a real project?

https://github.com/dotnet/efcore/issues/39569#issuecomment-6786874939

#CSharp #dotnet #EntityFramework #EFCore #opensource