Prism and ADO.Net Entity Data Framework

Topics: Prism v2 - Silverlight 2, Prism v2 - WPF 3.5
Jul 1, 2009 at 9:54 AM


  I am trying to use ADO.Net Entity Data Framework in Prism. Almost all the examples including talk about Silverlight page accessing. However in our applications, we use modules which are Class Libraries or Silverlight Class Libraries, which bind the data to the UI. Are there any code samples/snippets to use the same?

  Have uploaded the code sample at

  Thanks and regards,


Jul 1, 2009 at 7:41 PM

Pooran -

While I haven't taken the time to review your application, I am using EF in my application.

What I have done is the create my EF in a Data library, then during my shell init, I register the instance with the UNity container : 


this.Container.RegisterInstance<Entities>(new Entities(builder.ToString()));

Then in my views, I set the DataContext to the approriate set :

      public CensusPresentationModel Model
          get { return this.DataContext as CensusPresentationModel; }
              this.DataContext = value;
              if (value != null)
                  this.dg.ItemsSource = this.Model.ReferralEntities.ReferralSet;
                  this.dg.ItemsSource = null;

In this case, the CensusPresentationModel just has a ReferralSet property from the EF.

Then, binding as usual.


I am having an issue with refreshing the WPF Data Grid, but will start a new thread on that.
Hope this helps.

Jul 2, 2009 at 4:47 AM

Interesting.. will try that and get back to you.


Jul 2, 2009 at 4:55 AM

Is it possible to share the sample skeleton codebase of the data library? I am kind of stuck in the syntax.


Jul 2, 2009 at 3:07 PM
Edited Jul 2, 2009 at 4:53 PM

I'll try here -

First, this is just how *I* roll :)

In your Bootstrapper, register the service as such (be sure to call it from your CreateShell ):

        private void RegisterServices()
            //you need to have a conn string in the shell app.config for SampleDataEntities.
                new SampleDataEntities.SampleDataEntities(), 
                new Microsoft.Practices.Unity.ContainerControlledLifetimeManager());


Then in your view, I would add a property for your entities & set it as your DataContext :
IUnityContainer container;
IEventAggregator _eventAggregator;

public object Entities
            get { return this.DataContext as SampleDataEntities; }
            set { this.DataContext = value; }
 public AdminView(IUnityContainer container, 
                            IEventAggregator eventAggregator) :this()
            this.container = container;
            _eventAggregator = eventAggregator;
            this.Entities = this.container.Resolve();


Then your XAML can bind to the Entity directly Text = {Binding Path=users.Username......}

Couple of things - Not sure why you are using the ModuleManager in your view, you should likely be using the IRegionManager, but I've only browsed the code.
Also, it appears that you are implementing a webservice as a custom authentication and membership provider based on SQL.
While I don't have specific links, I *know* this has been done before, and likely the SqlMembershipProvder can take care of your needs with configuration. I've been immersed in WSS for awhile, so
some of those things can taint my mind.

Hope this helps.
Good Luck!
P.S. One thing I learned today - If you are going to use an EF Entity as a source, you likely need to wrap it in an ObservableCollection<>
this.Referrals = new ObservableCollection<Referral>( this.ReferralEntities.ReferralSet.ToList() );


Jul 3, 2009 at 4:27 AM

Thanks a lot for sharing the sample code.. I will give it a go and let you know.

Module manager in a view.. I have to bind few more modules and views in that view with custom regions. Not implemented yet though.

Webservice.. I might replace it with EF if that thing goes right. SqlMembershipProvider.. we are building a multiple logins including openid, live, and few other logins. So, custom implementation is what we preferred.

Thanks again :)