I am writing a WPF application, using an MVVM design with Entity Framework 4 as the ORM. I have collection properties in my view model that will contain collections of entities
I would probably use a factory pattern to achieve a level of abstraction in your viewModel if you want it.
The downside is that you will have to limit yourself to calling the factory every time you create one of your collections.
so if your factory had an API like this(which you could switch with whatever you wanted):
public static class ObjectBuilder
{
static Factory;
SetFactory(IFactory factory) { Factory = factory; };
T CreateObject() { return factory.Create();};
TCollection CreateObject>()
{
return Factory.Create();
}
TCollection CreateObject>(TCollection items)
{
return Factory.Create(TCollection items);
}
}
so now you would:
IFactory
to return your EdmObservableCollection whenever TCollection is ObservableCollection
ObjectBuilder.SetFactory()
ObjectBuilder.Create();
also if/whenever you would need to change your ORM backend you simply implement a new IFactory
and call ObjectBuilder.SetFactory(factory)