Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Recommended Approach to Data Access with WPF

Posted on 2009-07-07
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

One of the most frequent problems a "newbie" developer may encounter is having to deal with different data formats. One for all: THE DATE We, as humans, need to "see" a date and then interpret it (much of the times this is an automatic operation)…
How many times a day do you open, acknowledge, or close an IT incident? What’s your process? Do you have a process depending on the incident, systems involved, and other factors? New Relic Alerts gives you options for how you interact with notifica…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

661 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