I must discard all changes designed to linq tables (what this means is -- I personally use linq, and data are transformed on client side, the information on server are intact). How to get this done?
EDIT: problem partly solved
It really works as lengthy while you avoid using transaction. Whenever you do and also you use mixed "mode" for any record, there's an issue:
begin trans insert a record update inserted record commit trans
Whenever you update record as above Linq counts it as being up-to-date record, and just in case of exception you've two actions -- transaction is folded back and data on Linq side are thrown away. On discard changes Linq attempts to fetch it in the database (discard for update means refetching data for any record), consider all changes were folded back, there's no records for update.
How you can improve DiscardChanges method inside a wise general way to utilize transactions. Or how you can alter the workflow of transactions/discard-submitchanges to create all individuals interact?
Individuals aren't wise solutions:
- refetching all data
- re-creating link with DB (since it results in (1))
To increase what Johannes stated, I believe the confusion here comes from considering the
DataContext as something such as a
DataSet. It is not.
A "table" inside a
DataContext is sort of a hint regarding how to retrieve a particular kind of data entity in the database. Unlike a
DataContext doesn't really "contain" data, it really tracks the discrete organizations you've drawn from it. When the
DataContext vanishes (is disposed), the organizations continue to be valid, they're simply detached. This differs from a
DataSet in which the individual
DataRows are basically certain to their containers and can't outlive them.
To be able to make use of the
Refresh approach to a
DataContext, you should utilize it with an actual entity or assortment of organizations. You cannot "Refresh" a
Table<T> since it is not really an actual table, it is simply a type of reference.
Changes to organizations attached to a
DataContext are just endured whenever you call the
SubmitChanges method. Should you get rid of the
DataContext, there's no way the changes can persist unless of course you by hand reattach the detached organizations to a different
Simply discard the present DataContext without calling SubmitChanges() and customize the one.
DataContext myOldDc = new DataContext();