Reputation: 417
I have been trying to generate migration but some reason, generated migrations is empty except the basic definition of function up and down but empty inside.
Model class
public class StoryDB
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid id { get; set; }
[Required]
public string StoryContent { get; set; }
private int heartsCount { get; set; }
private int commentsCount { get; set; }
private int shareCount { get; set; }
public DateTime dateCreated { get; set; }
public DateTime dateModified { get; set; }
}
Database Context class
public class StoreDB : DbContext { public StoreDB() : base("DefaultConnection") {
}
public virtual DbSet <StoryDB> Stories { get; set; }
}
Note that I am using the same connection DefaultConnection which is used to by Identity Classes When I generate the initial seeding class that generates perfectly (i.e. all user tables like roles and users) However when i try to generate the first migration after seed class, then nothing appears in the class
Upvotes: 1
Views: 1357
Reputation: 2857
You have to tell the DbContext which entities you want to map to the DB. In your case StoryDB:
public class StoreDB : DbContext
{
public StoreDB() : base("DefaultConnection")
{
}
public virtual DbSet<StoryDB> Stories { get; set; }
}
Note that DbSet has a generic parameter, which tells EF the actual type to use.
Upvotes: 0