views:

36

answers:

0

I've set up a little n-tier web application using MVP (Model View Presenter) in the front-end, a WCF service on the backend, which communicates with the BLL an behind that the DAL, which communicates with the EF4.0. This is all working quite nicely, I've created several Get and Add methods which all work. Now I wanted to create several Update methods. Since I'm using the Self-Tracking Entities (STE) of the EF4.0, I thought everything would work out quite fine and implementation would be rather easy.

This doesn't seem to be the case. When changing my items in the web front-end, they keep having the status Unchanged when moving back to the WCF-service. Because the entity is unchanged, nothing gets updated in the database. Through this question on SO: http://stackoverflow.com/questions/2166393/ef-4-self-tracking-entities-does-not-work-as-expected I came accross the article telling something more in detail about implementing the STE's with in an n-tier application. (http://msdn.microsoft.com/en-us/magazine/ee335715.aspx) I quote:

Make certain to reuse the Self-Tracking Entity template’s generated entity code on your client. If you use proxy code generated by Add Service Reference in Visual Studio or some other tool, things look right for the most part, but you will discover that the entities don’t actually keep track of their changes on the client.

Well, I've managed to create a client to the service using this code:

var svc = new ChannelFactory<INorthwindSTEService>(
    "INorthwindSTEService")
    .CreateChannel();

This appears to work quite alright. The thing is, how do I get the serialized entities on the client? In the code example I'm seeing the writer uses this code:

var products = new List<Product>(svc.GetProducts());
var customer = svc.GetCustomer("ALFKI");

But I fail to see where those objects/entities/??? are defined (I'm talking about a Customer and a Product)

I've tested it using the entities which were created using the Add Service Reference, but that doesn't seem to work. The returned entities still have the status Unchanged.

I'd rather not reference the EF entities in my front-end, because I'd like to keep them separated and only have serialized objects on my front-end. Though, if it is really necessary, I might just have to do that.

Oh, using the MarkAsModified() method on the entity object does work nicely though, but that's more of a hack as the entity should check his status by itself.

Any advice on how to proceed? My guess is using the MarkAsModiefied() method or referencing the entity models project in my web application could be viable work-around, but if there's something better, I'd like to try that first.