Entity Framework

Entity Framework

Old forum URL: forums.lhotka.net/forums/t/6923.aspx


MikeB posted on Sunday, May 10, 2009

Rocky,

I have just got back from a 250 mile journey to buy your book. Well, I went to see the play We Will Rock You in Toronto, Ontario as well, but believe it or not, it was the closest bookstore to my house that had the Expert c# 2008 book. I am really interested in using CSLA with Entity Framework as the data access layer. In your book you state that the Project Tracker will be reworked to include an example using the Entity Framework. Is this still on your plate of "things-to-do"?

I haven't started designing my application yet, but I am tossing around the idea of using CSLA or my own WCF services classes....

Great book and Framework BTW!

Mike B

RockfordLhotka replied on Monday, May 11, 2009

Unfortunately that is still on my list of things to do.

The challenge for me, is that it is rather boring work. The use of EF is very similar to the use of L2S shown in the book. The only real differences are that EF has crappy support for stored procedures, so I need to abandon them, and that there are some entity identity concepts in EF that require (potentially) storing an extra data field in the business objects to track the relationship back to the entity.

That's not to say I won't get around to it at some point, but it hasn't floated to the top of my list, and probably won't for a while (I have to finish a bunch of M/Oslo work, the Silverlight video series and start working on support for SL 3).

Honestly, I'm far more interested in EF version 2, which is perhaps a year out (?), but should make things much better (I hope).

MikeB replied on Monday, May 11, 2009

Thanks for the reply. That is unfortunate that there is no example. I could really use the guidance since both frameworks are pretty new to me....

I was wondering if you can tell me if I am on the write track. I created the beginnings of my Entity Framework model. I also created my first BusinessBase derived class EmployeeBO.

In the DataPortal_Fetch(...) I use the Entities context to load the employee, then from there, I use ReadProperty to set my business object.

protected override void DataPortal_Update(SingleCriteria<EmployeeBO, int> criteria)

{

   using (InformEntities entities = new InformEntities())

{

   var emp = (from e in entities.Employees where e.EmployeeId == criteria.Value select e).First();

   LoadProperty(IdProperty, data.EmployeeId);

   LoadProeprty(FirstProperty, data.First);

   etc...
}

}

I was wondering, does the Employee object from the entity framework get disposed at this point? Or do I have to call anything to dispose it?

 

Mike Bujak

 

crussi replied on Monday, May 11, 2009

Mike,

Sergey Barskiy upgraded the Silverlight Rolodex example to use EF.  I am thinking the DAL should be similar for both WPF and Silverlight.  You can see this post to find the download from his blog http://forums.lhotka.net/forums/thread/31324.aspx . 

Chris

MikeB replied on Tuesday, May 12, 2009

Thanks, I will check it out.

 

Mike B

MikeB replied on Tuesday, May 12, 2009

Well, unfortunately I cannot load the projects. I am assuming the Rolodex application was done in Silverlight? I try to load it and get an error "The project type is not supported by this installation".

 

Anyway, I can see his EF classes and the Business classes and was going through those. In his factory methods, he uses the DataPortalClient and DataPortalResult. I am wondering what does the client application have to do to create an object?

 

I have looked through Expert c# 2008 book and found that this is to use the fetch in asynchronous mode. My only problem is that I cannot see how it is used in the client. Any help or examples?

public static void GetCompany(int companyId, EventHandler<DataPortalResult<Company>> handler)

{

   DataPortal<Company> dp = new DataPortal<Company>();

   dp.FetchCompleted += handler;

   db.BeginFetch(new SingleCriteria<Company, int>(companyId);
}

 

Mike B

Copyright (c) Marimer LLC