How can I make EF Core database first use Enums?

后端 未结 7 977
灰色年华
灰色年华 2020-12-06 04:43

I\'m using EF Core with database-first approach using the \"Scaffold-DbContext\"-command to generate my DbContext / Entities.

How can I instruct Scaffold-DbContext t

7条回答
  •  天命终不由人
    2020-12-06 04:54

    Currently, EF core does not support enums. Code like this:

    public class MyDbContext : DbContext
    {      
        protected override void OnModelCreating(ModelBuilder builder) 
        {
            builder.Entity(e => {...});
        }
    }
    

    does not compile with the message:

    CS0452 C# The type must be a reference type in order to use it as parameter 'TEntity' in the generic type or method

    Solution: you can use enumeration classes instead

提交回复
热议问题