WPF and LINQ/SQL - how and where to keep track of changes?
Posted
by Groky
on Stack Overflow
See other posts from Stack Overflow
or by Groky
Published on 2009-12-16T01:54:56Z
Indexed on
2010/03/14
18:05 UTC
Read the original article
Hit count: 240
wpf
|linq-to-sql
I have a WPF application built using the MVVM pattern:
- My Models come from LINQ to SQL.
- I use the Repository Pattern to abstract away the DataContext.
- My ViewModels have a reference to a Model.
- Setting a property on the ViewModel causes that value to be written through to the Model.
As you can see, my data is stored in my Model, and changes are therefore tracked by my DataContext.
However, in this question I read:
The guidelines from the MSDN documentation on the DataContext class are what I would recommend following:
In general, a DataContext instance is designed to last for one "unit of work" however your application defines that term. A DataContext is lightweight and is not expensive to create. A typical LINQ to SQL application creates DataContext instances at method scope or as a member of short-lived classes that represent a logical set of related database operations.
How do you track your changes? In your DataContext? In your ViewModel? Elsewhere?
© Stack Overflow or respective owner