问题
Reading the msdn information on EF 5.0 and n-tier solutions see link , it seems that MS is not recommending STE's and the POCO/DTO way is also not recommended by stating that it is difficult.
Not all (perhaps not many?) applications are suited for using WCF Data Services. So what is the way to go? My scenario is a current, large server (WebServices) application with many clients (only our own), mostly WinForms. Today DataSets are used to ship the data and track changes into the SQL Server database.
We are now starting to replace WebServices with WCF and are also looking into using the Entity Framework. We don't need code first or migrations since we already have the database in place and a lot of stored procedures that will be reused. Since we don't have any issues with clients being other than our own, STE's seemed like a good choice, but we don't want to start using something that the EF team is clearly not recommending anymore. POCO/DTO has also been an alternative, not least for the clear separation against the clients. I know there is more work to be done then with the CUD, but is it so difficult that the recommendation is to stay away, then I don't know if we want to go down that road.
Then, according to the recommendation we should use WCF data services or Web API, but that is really not an alternative for a operation-based service that needs to be flexible about protocol/format etc.
So my question is, what is best-practice today?
回答1:
I think the idea is to move more generally to lighter weight pocos/dtos and keeping any an all persistence logic or implementation in your DAL. Self tracking entities sort of bleed some of that implementation out and fatten up your entities. You gain convenience, but loose flexibility as dumb dto's can be passed around easily with few suprises.
Of course the flip side to that is you need to do more work in your dal to track context and you need to do more work in your BLL and UI to deal with populating/mapping dto's.
I personally prefer flexibility over convenience and that seems to be the way things are going in general.
来源:https://stackoverflow.com/questions/12456905/self-tracking-entities-not-recommended-anymore-what-is