views:

19

answers:

1

Hi all,

I have question about Entity Framework. I did a search here but could not find a very good solution. I maybe be using EF in a strange way that is not typical.

Basically I declare a context on the start of my appliction and load the data I need. I'm using MVVM design patern for a C# WPF desktop application with a SQLite backend.

This context is passed to my different ViewModels to load from. They load the entites and create needed VM based on them. Certain Views have a Save button to save the changes for that ONE ViewModel.

Basically I just call the SaveChanges method of my context.

My problem is: I am using one context and there are other VM that are completely unrelated and changes made on these View should only be persisted when the corrosponding save button is pressed.

Is there a way to persist only the entities I choose? (I could handle figuring out which entites to persist very easily) I am sure that MS did not design an ALL OR NOTHING approach with it's changes but I may be using contexts incorrectly.

A: 

I do not yet have a solution for this but I thought that since nobody has responded that I will add some more details.

In an N-Tier application, the entity objects would be serialized using self tracking entities. This makes things very easy because you use a WCF service to transfer the objects but this service contains methods like Service.UpdateEntity(Entity) and it smiply handles applying the changes in the entity and saving them to the database. This is EXACTLY the kind of method I need for my SINGLE-Tier application but does not exist.

How can I get this functionality in a Single-Tier approach using Entity Framework? Do I have to use AutoMapper + hand coded DTO like objects? Does EF only provide this functionality for N-Tier leaving single-tier to be more complicated and difficult??

I have been doing alot of research on this topic and I am starting to think that I am the only person who is having this problem which is very sad. Am I missing something obvious?

Mike Bynum