Recommended Approach to Data Access with WPF

Posted on 2009-07-07
Last Modified: 2013-11-11
Is there a Microsoft recommended choice of Data Access Layer (DAL) for use with WPF? If not, what options are available and what are the features/advantages/disadvantages of each approach?

The options seem to be:
1. Using Entity Framework with WPF
 - This supports PropertyChanged and PropertyChanging events
 - This does not use a POCO model by default
 - To use a POCO model the following framework is provided

2. Using Linq objects
 - These do not support PropertyChanged and PropertyChanging events by default
 - Some templates are available in the community to support these events

3. Other DALs such as SubSonic, CSLA.NET, Sculpture .NET etc
 - These support PropertyChanged and PropertyChanging events

4. Reflection Emit of data access objects

Note: there may be a requirement to support Silverlight.
Question by:DevelopersAnonymous
  • 3
  • 2
LVL 55

Expert Comment

by:Jaime Olivares
ID: 24801059
well, let's start with the more constrained requirement: silverlight. It doesn't support database directly. You have to use an intermediary WCF service to have database access.
About PropertyChanged events, it is not related with DAL at all, but with business layer and closely related with presentation layer.

Author Comment

ID: 24801414
Hi jaime_olivares,

Thanks for your response.

Firstly, Silverlight still has to bind to a data object (and yes it must be retrieved from a WCF or web service). I define a data object as a code representation of the table or view or type generated from a stored procedure. The data objects are contained in DAL assemblies, this is called the data layer.

A business object in a system will use these data objects from the DAL (and preferrably the UI for the system will use these data objects as well). Thus the data objects must support the PropertyChanged, PropertyChainging or other events that you might want to add (say with aspect injection).

I also should have said that our preference is that our DAL supports stored procedures, apparently this is not done very well with entity framework. However there is a library on codeplex called EFExtensions that massively improves the handling of stored procs.

Idealy, I would like to emit the EF framework objects and then use them in memory without reflection so that I get super fast performance and type safety.
LVL 55

Expert Comment

by:Jaime Olivares
ID: 24803774
>>A business object in a system will use these data objects from the DAL (and preferrably the UI for the system will use these data objects as well)

Ideally PL shouldn't know about data objects, just about bussiness objects, because BO use to have some extra logic inside to validate or calculate some fields, or generate more than one data transaction per each bussiness transaction.
So, what you expose in webservice are bussiness objects, not data objects at all.

The update control should be done at BL and not at DL, because the reasons exposed (some fields to validate/calculate or extra transactions), although Entity Framework can help BL in ensuring relational data integrity.
What is definitive is that you cannot use Entity Framework objects into your silverlight application unless you expose them in a service contract, but this will move your BL to the silverlight app itself, which is basically just a presentation layer.

Author Comment

ID: 24811694
Hi jaime_olivares,

Thanks again for your response.

I agree with you that in times past it was important to maintain seperate Data Objects and Business Objects, but in the modern world of scaleable stateless architectures, this is no longer important. Our data objects reside in a shared layer which is accessible by the DAL, BLL and PL. I never suggested that updates would be propegated at the DAL, they will occur at the BLL.

We have narrowed our choice of DALs down to:
 - Entity Framework with EFPocoAdapter and EFExtensions
 - Linq objects
 - Sculpture .NET

Our main considerations with these are:
 - Support of POCO
 - Support of PropertyChanged and PropertyChanging events

We are seeking:
 - Knowledge as to whether Microsoft has a recommended approach to this problem when dealing with WPF.
 - A comparison of the features/advantages/disadvantages of these DALs
 - Any user experience/recommendations

Accepted Solution

DevelopersAnonymous earned 0 total points
ID: 24836561
There appears to be no Microsoft 'best practice' as far as this goes. We have settled on Entity Framework with the aforementioned extensions.

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question