WCF + Entity Framework design
I was wondering how to design this best..
On my ASP.NET MVC application I have a database and I want to use a WCF to han开发者_开发知识库dle all my interaction with that database through EF. So I've create a Entity Model on the service which I use to interact with the database. In order to interact with the WCF from the ASP.NET app I've created DTO's for each EF model (I only have 3) and a Converter class to convert from the EF models to the DTO's and vice versa.
On a side-note.. would it be possible to avoid using DTO's and just transfer the EF models instead? - I've tried, but with no luck as the client asp.net app doesnt recognize these models.
Is this a suitable way of designing this or would another approach be better?
Thanks in advance. :)
This architecture is indeed used in situations where business logic and data access logic is deployed on another server then asp.net frontend. Reason for such architecture can be company policy, security, scalability, etc. But usually it is for bigger projects.
You said that you have 3 "EF models". Does it mean that you have 3 EDMXs files or 3 entities? If you mean 3 entities than your project is probably very small and unless you really must use this architecture (direct requirement) or unless you are doing just some test project there is no reason to do that.
How do you use DTOs? Is it just (or very close) 1:1 mapping to EF entity? In such case you missed DTOs purpose and you most probably don't need them. If your service exposes CRUD operations you can use EF entities directly (but you must use POCO or STE).
Moreover if you just want to expose EF model as CRUD service you should check WCF Data Services.
精彩评论