1

I want to build a WPF application that can support multiple data sources, local and remote. There is a configuration that switches between 2 modes. What I'm planning is:

  • Client: WPF application with MVVM Framework.
  • Local data source: SQL Server 2012 and Entity Framework 6.
  • Remote data source: WCF data services.

Both local and remote data sources share the same data model. The problem I'm facing is the objects returned from local and remote data source are different. For instance:

  • Local: Project.Model.Employee
  • Remote: Project.WCFDataService.ServiceReference.Employee

For this reason, I can't bind objects to WPF Views. Is there any easy/safe way to convert these objects? Any other suggestions?

Huy Le
  • 23
  • 1
  • 3

1 Answers1

1

The first thing you need to do is map (translate) the EF objects into standardized data entities that you use throughout your application (and also return from your WCF services). There's probably a million examples of how to do this in a generic way using reflection (here is one), but direct mapping (projecting) using code is also an option and is faster than reflection. An ORM is an option but be careful that you don't over complicate things by introducing components you don't really need.

Sharing data entities between WCF and any sort of client application is well documented (quick and dirty search: 1, 2, 3, 4).

As for querying both data sources, use a SOA approach. The view model calls a "service" method to get its data, and the service is responsible for calling both the local data repository and the remote WCF service then combining the result.

Community
  • 1
  • 1
slugster
  • 49,403
  • 14
  • 95
  • 145