Uso de EntityFramework a través de fronteras en sistemas empresariales

We are starting work on a new enterprise application and are currently considering the technology stack.

It's going to be .Net/SQL Server as that is what we all know.

The application is going to have different UI's for different platforms e.g Web, Desktop WPF, Mobile because of this we were looking at creating WCF services to house our Business/Data Logic so each UI can just call in to the same logic.

We would like to also use Entity Framework Code First but in the past when we've tried it EntityFramework has never been that great when you start passing Entities across boundaries e.g change tracking is lost and you have to start manually working out how to update entities and checking which child entities have also been changed.

Have these problems been solved in newer versions of WCF/EntityFramework? Are there any examples or patterns we could look at to ease this process? Or Should we avoid EntityFramework in this scenario?

preguntado el 04 de julio de 12 a las 08:07

Why would you pass an active entity across domain boundries? -

Maybe I'm looking at this wrong, but if I want to grab data say a Book object from the database and use it in my web app I would call GetBook from the WCF service to get my entity back, make changes in the WebApp then call SaveBook on the WCF service passing in the modified book object. -

It seems like you just want your WCF service to act as a proxy to the database, if this is the case then why have the service at all? If you are doing more logic than just crud in your service (such as permissions and validation) then you probably dont want to directly call a entity wide save method, you would be better to call an UpdateTitle method. I also dont really agree with models crossing 2 domain boundries as it produces really tight coupling, if you added a IsDeleted column would you want that propogated to all other systems? -

The idea was to keep the client as dumb as possible and keep all business and data access logic in services to maximize reuse across clients. I appreciate this may be a bad idea just really looking to get opinions. -

Ok that makes sense, IMO you should build an API to surface your data which provides a set of actions which you can perform and a set of data queries you can execute. If you are doing this your WCF methods would be fairly simple and action based (not data based) such as WithdrawBook or ReturnBook. In terms of your queries you could present several versions of FindBook to allow for different ways to query. Personally (and most people don't actually do it this way but its my preference) i wouldn't return the book entity from the database I would return some kind of transport model. -

1 Respuestas

Have these problems been solved in newer versions of WCF/EntityFramework? Are there any examples or patterns we could look at to ease this process? Or Should we avoid EntityFramework in this scenario?

No they haven't. If you don't use EF and you will use WCF and SQL directly how will your WCF know what data has changed on the client? Yes, you will have to implement a mechanism either by passing some additional information in data or by checking current state in the database. The same approach is needed for EF if you don't move this change detection to client.

If you are happy with moving change detection to client and your service layer is more like a gateway to database use WCF Data Services - they will handle change tracking across boundaries for you but your client applications will have to use WCF Data Service generated client.

Respondido 04 Jul 12, 16:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.