WCF - Entity Framework, returning objects to client
I have a WCF API which is being called by a .net client, i am trying to return a Entity Framework object (db object) to the client, is this bad practice? Should i use reflection to dump the data into an object that has less accesability and reurn that instead?
The error i get when the client calls the API is:
The specified na开发者_如何学JAVAmed connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
any help would be appreciated.
If your entity model aligns properly with what you would use as the Data Transfer Object over the wire, then I would say yes, there's nothing wrong with passing the entity object back.
However, I would recommend using the POCO Entity Generator to make the entities more lightweight (so that they align better with what DTOs should be).
As for your error, that is a separate issue, related to not being able to find the appropriate named connection in the config file, or the connection string existing but not being set up correctly (as the error indicates).
We're returning EF objet over WFC without any issues. However, all of you clients are .Net clients. You might run under issues if you use self-tracking entities on non-.Net clients (self-tracking entities are useful to enable saving modifications made client side easily, i.e. contextless).
精彩评论