Tuesday, 15 March 2011

wpf - ObjectContext in ViewModel (EF + MVVM) -


I am currently writing my first MVVM application which uses EntityFramework for data access. This application relies heavily on the underlying database and in many cases DB has to add new data.

However, I have uncertainty about whether this is a good idea that the object Konteks should see the modal. Like Public Class Somewhile Model: See Modellabase {Public INMereble & lt; Users & gt; AllUsers {Get; Private set; } Private Zero Certain Methods () {var __entities = New Databases (); AllUsers = __entities.Users.Where (...). ToList (); }

}

I have seen such solutions, but there are some questions to come up with. For example, how long the object syntactic remains, or if a single, global accessible object might like to present.

Or should call those who are not part of VM at the first place? At present, I can also imagine that implementing the same as Static Helper for each DB table and using methods like GetAllUsers ().

An application about MVVM in Josh Smith's sample that he injects into every VM constructor.

  Public AllCustomersViewModel (CustomerRepository customerRepository)   

Despite the fact that this should be a general problem, I have not received any satisfactory answer on this How has the issue been delivered to the small application (best practice)?

In this description of DBCText class on MSDN, so it should act as its repository layer , Although it is not, and it has to be used for "unit of work" which is not suitable for the entire app for a global use. Apart from keeping around for each one, there can be problems with cached data and other undesirable things (memory usage, etc ...).

Hope this will be helpful.

No comments:

Post a Comment