Hello guys so i've tryed some ideas over internet to fix this issue and all have faild so that why i'm writing this so maybe someone can help me in entity framework latest version:)
using (var ctx = new ESContext())
{
quote =
ctx.HB_Quote.FirstOrDefault(x => x.ID == issuesContract.EvidenceContract.QuoteContract.ServerID) ??
new ESModel.HB_Quote()
{
ID = issuesContract.EvidenceContract.QuoteContract.ServerID ?? 0,
QuoteLegend = issuesContract.EvidenceContract.QuoteContract.QuoteLegend,
QuoteText = issuesContract.EvidenceContract.QuoteContract.QuoteText
};
if (issuesContract.EvidenceContract.QuoteContract.ServerID == null)
{
ctx.HB_Quote.Add(quote);
}
else
{
ctx.Entry(quote).State = EntityState.Modified;
}
ctx.SaveChanges();
}
using (var ctx = new ESContext())
{
imageLibrary =
ctx.HB_ImageLibrary.FirstOrDefault(
x => x.ID == issuesContract.EvidenceContract.ImageLibaryContract.ServerID) ??
new ESModel.HB_ImageLibrary()
{
ID = issuesContract.EvidenceContract.ImageLibaryContract.ServerID ?? 0,
Conclusion = issuesContract.EvidenceContract.ImageLibaryContract.Conclusion,
Image = issuesContract.EvidenceContract.ImageLibaryContract.Image,
Title = issuesContract.EvidenceContract.ImageLibaryContract.Title
};
if (issuesContract.EvidenceContract.ImageLibaryContract.ServerID == null)
{
ctx.HB_ImageLibrary.Add(imageLibrary);
}
else
{
ctx.Entry(imageLibrary).State = EntityState.Modified;
}
ctx.SaveChanges();
}
the last part co using this error:
An exception of type 'System.Data.Entity.Infrastructure.DbUpdateConcurrencyException' occurred in EntityFramework.dll but was not handled in user code
Additional information: Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=472540 for information on understanding and handling optimistic concurrency exceptions.