views:

27

answers:

0

Let's say I have an app and a web site using the same database. I wan't to create a Data layer and some model objects. In many cases the model objects uses alot of info from some of the database tables.

My idea was to wrap the LINQ to SQL entity class for the table inside the view so I won't have treate the properties again. I was wondering how that will work with INotifyPropertyChanged and IEditableObject.

I'm gonna give an pseudocode example of a Model where a user table in database has to be able to be viewed and changed in a WPF app and viewd on a website.

public class UserModel
{
 //the linq entity
 public User theData;

 public UserModel( User user)
 {
     theData = user;
 }

 public Save()
 {
     //Open Datacontext, find user and save changes, or create new if he doesn't exist
 }
}

Now in the WPF app I would use two-way bindings to the properties of the theData property so it would have to have OnPropertyChanged set, is this something that's done automatically in LINQ entities?

Also instead of going straight to the textboxes the Users would be viewable and then they would have edit buttons that would put the object into edit mode ( using IEditableObject ). Is this interface used in the LINQ entities and if not could I use it on the UserModel class and somehow clone the theData object to cache it before changes?

Now when people use MVVM design pattern how would one go about doing this part?