suman goud

suman goud

  • NA
  • 176
  • 54.1k

How to fix model backing error while inserting data in mvc4

Aug 4 2016 7:02 AM
am getting following error when am inserting data

The model backing the 'ReceiptsDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database

 mymodel
public class Transaction_GeneralInfo
{
[Key]
public string CompanyName { get; set; }
public int VNumber { get; set; }
 }
public class Accounting_PendingBills
{
[Key]
public String Branch { get; set; }
public string Currency { get; set; }
public string CompanyName { get; set; }
public class ReceiptsViewModel
{
public String Branch { get; set; }
public string Currency { get; set; }
public int VNumber { get; set; } 
public string CompanyName { get; set; }
}
public class ReceiptsDbContext : DbContext
{
public DbSet<Accounting_PendingBills> pendings { get; set; }
public DbSet<Transaction_GeneralInfo> transactionGeneralInfo { get; set; }
}
 
 
public ActionResult Index(ReceiptsViewModel receiptsModel, string Command)
{
if (Command == "Save")
{
ReceiptsDbContext db = new ReceiptsDbContext();
var transaction = new Transaction_GeneralInfo()
{
CompanyName = receiptsModel.CompanyName,
VNumber = receiptsModel.VNumber
};
var pending = new Accounting_PendingBills()
{
Branch = receiptsModel.Branch,
Currency = receiptsModel.Currency,
CompanyName = receiptsModel.CompanyName 
};
db.transactionGeneralInfo.Add(transaction);
db.pendings.Add(pending);
db.SaveChanges();
}
 
 

Answers (4)