0

I created models and performed code first migration which resulted in prepopulated up down methods. However at a later stage I added new models to my application. The new models I added were Cart, OrderDetails and Order. I then typed add-migration for each of these models which as a result produced empty up down methods.

I would like to ask why are these up down methods empty when I added a new model. I referenced these models in the dbcontext, the same dbcontext that referenced previously created models.

These are the new model classes that I added:

public class OrderDetail { public int OrderDetailId { get; set; } public int OrderId { get; set; } public int BookId { get; set; } public int Quantity { get; set; } public decimal UnitPrice { get; set; } public virtual Book Books { get; set; } public virtual Order Order { get; set; } } public class Cart { [Key] public int RecordId { get; set; } public string CartId { get; set; } public int BookId{ get; set; } public int Count { get; set; } public virtual Book Book { get; set; } } class Order { public int OrderId { get; set; } public string Username { get; set; } public string FirstName { get; set; } } 

Here is my dbcontext

public BookStoreOnlineDB() : base("name=BookStoreOnlineDB") { } public System.Data.Entity.DbSet<BookStoreOnline.Models.Book> Books { get; set; } public System.Data.Entity.DbSet<BookStoreOnline.Models.Author> Authors { get; set; } public System.Data.Entity.DbSet<BookStoreOnline.Models.BookStatus> BookStatus { get; set; } public System.Data.Entity.DbSet<BookStoreOnline.Models.Genre> Genres { get; set; } public System.Data.Entity.DbSet<BookStoreOnline.Models.Order> Orders { get; set; } public System.Data.Entity.DbSet<BookStoreOnline.Models.OrderDetail> OrderDetails { get; set; } public System.Data.Entity.DbSet<BookStoreOnline.Models.Cart>Carts { get; set; } } 

In summary, how do I populate the new up down methods with regards to the newly added Cart, OrderDetail and Detail models.

N.B. The orderDetails model and cart model reference the book model(book model contains had data migration performed on it at an earlier stage and contains populated up down methods).

New to this and would really appreciate help. Thanks

5
  • Try running Update-Database -Script -SourceMigration $InitialDatabase. Does it generate a script with your prior objects? If you are not too far along just reset your migrations Commented Nov 10, 2016 at 18:29
  • @SteveGreene Did not work but thanks anyways Commented Nov 13, 2016 at 21:52
  • 1
    Your question says add-migration had no code. Your solution says add-migration now has code. What did you do different or change? Commented Nov 14, 2016 at 17:07
  • I typed add-migration intitialcreate as appose to add migration orderdetails Commented Nov 14, 2016 at 19:59
  • 1
    Assuming you meant "add-migration orderdetails", then it would make no difference. "initialcreate" is just a user defined label and does not affect creation of the migration itself. Commented Nov 14, 2016 at 20:04

1 Answer 1

-1

Answer: in PM Console: add-migration initialcreate //this included the newly added models e.g their ids,(cart,orderdetails, order models) to the up down methods

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.