question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Make Scaffold generate field as CLR Enum

See original GitHub issue

Hello! I use ef core database-first approach in my project, and I have a table that is described with the class

public class Item
{
  public int Id { get; set; }
  public string Name { get; set; }
  public int Status { get; set; }
}

public enum Status
{
  New = 1,
  InProgress = 2,
  Complete = 3
}

I want Scaffold to make Item.Status property as Status type. Is it possible to point out to use a pre-defined enum for some fields when using Scaffold?

I found a post on SO (https://stackoverflow.com/questions/44262314/how-can-i-make-ef-core-database-first-use-enums), but the answer is for code-first approach

EF Core version: 6.0.3 Database provider: Npgsql.EntityFrameworkCore.PostgreSQL Target framework: . .NET 6.0 Operating system: Windows 11 IDE: Visual Studio 2022 17.1.1

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ErikEJcommented, Oct 11, 2022

@rmcp Yes, if you combine with .t4 templates.

0reactions
rmcpcommented, Oct 11, 2022

Is it possible to achieve this using CLI?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Entity framework Core - Scaffolding enum
Context: I use Database-first approach to generate my entities with Entity Framework Core and with use of Scaffolding. · Problem: I would like...
Read more >
Enum Type Mapping
You will have to create the CLR type, add the global mapping and add the properties to your entities. In the future it...
Read more >
How to use Enums when using Entity Framework Core with ...
Our first option was to model the enum as a separate table and use an unmapped property to cast it to an enum,...
Read more >
Value Conversions - EF Core
Configuring value converters in an Entity Framework Core model.
Read more >
Entity Framework Core: Enums
Enum support in EF Core is quite extensive, in this article I'll cover how to use an enum as a Primary Key, as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found