Reputation: 4657
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 : DbContext
{
public DbSet<string> Keys { get; set; }
}
but when I try to run the code I get this exception:System.InvalidOperationException
: The type 'System.String' was not mapped. Check that the type has not been explicitly excluded by using the Ignore method or NotMappedAttribute data annotation. Verify that the type was defined as a class, is not primitive, nested or generic, and does not inherit from EntityObject.
How can I resolve the problem?
Upvotes: 3
Views: 3165
Reputation: 31620
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.
Upvotes: 4