Use string as type of DbSet like DbSet in EF-CodeFirst

前端 未结 1 1861
陌清茗
陌清茗 2021-01-20 06:53

I want to have a list of string and save and load them to/from database using EF-CodeFirst. this is my DbContext class:

public class KeysDbContext : DbContex         


        
相关标签:
1条回答
  • 2021-01-20 07:50

    You cannot have a DbSet<string>. String is treated as a primitive type by EF and the type for the DbSet has to be an entity. Entity has properties (which usually are mapped to columns in database) and also have to have keys. If, in your database you have a table that has just one string column you would have to create an entity with a string property to model this. In addition the string property will have to be a key property.

    0 讨论(0)
提交回复
热议问题