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 pendings { get; set; }
public DbSet 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();
}
4 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Rajeev PunhaniPosted Aug 4, 2016, 1:21 PM
If the above solution is helpful then,accept the answer.
Vinay SinghPosted Aug 4, 2016, 8:04 AM
suman goudPosted Aug 4, 2016, 7:55 AM
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
Rajeev PunhaniPosted Aug 4, 2016, 7:13 AM
Hi Suman ,
Please add thefollowing line in your Application_Start event.
If the above solution is helpful then,accept the answer.