Im working on a MVC3 project using code first entity framework. On a webpage a button is pushed.
Part of what happends is that a Sale-object is created to be saved in a database:
var newSale = new Sale
{
Id = Guid.NewGuid(),
Material = material,
Buyer = buyer,
CashOut = null,
Token = response.Token,
TimeStamp = null
};
dataContext.Add(newSale);
dataContext.SaveChanges();
After you will be redirected to another controller function that edits the value of the TimeStamp-property of the Sale object.
var dataContext = FOSDataContextFactory.Create();
var = dataContext.Sales.SingleOrDefault(x => x.Token == tokenId);
if (sale != null)
{
sale.TimeStamp = DateTime.UtcNow;
dataContext.SaveChanges();
}
When im steping through the code using the debugger everything works fine and the TimeStamp - property is changed. But when running the web-application without debugging the code a error occurs:
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
This is the error that i got:
Entity of type: Sale_9C4571E6D8D390FBA94D51E54B356016DF8C20533C767502369B99F24C117B5B in state: Modified - Property: Material, Error: The Material field is required. - Property: Buyer, Error: The Buyer field is required.
What can be the cause of this problem?