this is When a new record is inserted From Client A into server :
var Invoice = new Invoice();
foreach (DataGridViewRow item in DataGridView1.Rows)
{
Invoice.InvoiceDetails.Add(new InvoiceDetail
{
Description = txt1.Text,
TotalPrice = txt2.Text
});
}
dc.Invoices.InsertOnSubmit(Invoice);
dc.SubmitChanges();
ok now imagine client 2 is going to edit this record.
var Invoice = dc.Invoices.First(p => p.ID == _InvoiceID);
dc.InvoiceDetails.DeleteAllOnSubmit(Invoice.InvoiceDetails);
foreach (DataGridViewRow item in DataGridView1.Rows)
{
Invoice.InvoiceDetails.Add(new InvoiceDetail
{
Description = "Description",
TotalPrice = "10000000"
});
}
dc.SubmitChanges();
now here is the thing.Client one has the first 2 invoices that IT inserted itself still residing in its DataClass.
meaning the two clients have two different DataClasses Localy on RAM.
problem starts when client 1 Goes For another edit AGAIN :
When Selecting the Invoice again using :
var Invoice = dc.Invoices.First(p => p.ID == _InvoiceID);
currently this invoice on client 1 has the 2 it added itself to the db,still on its dc.so with this select it will also add the 2 from the DB that the client 2 added from the server.
so the problem is client 1 will show you 4 Details instead of 2,containing 2 from the Server system,and 2 from its local DataClass.
i just got informed that its called Data Concurrency.
Please note that the data context is static and public and is kept alive through the whole applications lifetime. I know this is wrong and it has to be kept short but the data is massive and i cant just make a new data context on every form.
Looking for solutions as im already switching to entity framework for the fix but i need to apply a solution to the current state of the application untill im done switching to the entity framework.
Also one more thing, the app creates its database so sprocs are not an option as t linq cant create em with createdatabase().