开发者

MVVM With EF, DataAccess design question

First and foremost. Sorry about my English, i'm still learning :)

I'm currently wrestling with the MVVM model.

  • At the bottom, i have a database.
  • On top of that sits my DAL which is bascily the ADO.NET entity framework. *Note that the different entities are also my business objects (since i include validation in them).
  • On top of that again, i have repository classes which define the different queries required in the app.
  • And ofcourse on top of that i got things like the interface, other components and unit testing but i dont think that's really relevant.

The situation is as the following (in abstract): On top of the repository pattern, there is a worker performing all kinds of tasks. Next there is an interface which shows the status of these different tasks. (Each task containing tons of subtasks). Both the interface and the worker share the same Repository of the tasks!

Now what i'm trying to achieve is this: The worker might open (or expand if you will) a task, processing all its subtasks. At some time, the user might expand the task in the interface seeing all the subtasks. Ofcourse it would be great to see the subtasks beeing updated开发者_开发问答 once there beeing processed by the scheduler. Yet, by default i dont want to have the subtasks loaded in memory when not beeing processed or shown. Therefore the subtasks should load on demand.

Now my question, when one of the consumers open a repository for the subtasks of a task, Whats the nicest way of sharing it with other consumers (this is required, because the repository raises the events when things change)? (e.g. how to share the repository created by the worker with the interface).

Most notably, you would say that it will become a property of the Task entity, but because the Task entity is used a business object, it should not have the knowledge of either the underlying datasource (in this case the EF model), or the Repository layer on top of it.

Another option would be to create add a LoadChildTasks method to the Tasks repository but that would mean that i have to keep a collection internally and when the load is called, check if there wasn't a SubTaskRepository created before for the Task specified. Also it would mean that when both the interface and the worker dropped their operations on the task list, it needs to be manually released because else it would be held in memory by the internal list.


we make the repository class as singleton class. so it will be shared in whole application. hope this will help. Jane

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜