Reputation: 185
I am having a question that can Web-Serivces
like WCF
, SOAP
, REST
etc work hand-in-hand with entity framework ?
I have created a project in which I have used entity framework's database first approach and it works well for now. but now I am having an requirement to integrate Web-Service
in that project.
So I want to know whether or not the Web-Services
will work with my existing Entity Framework structure or else I will have to remove all the entity framework thingy and create only Web-Services
?
Upvotes: 2
Views: 8614
Reputation: 33
I don't know if you are happy with that, but you can use sth like Repository pattern with Entity Framework. Then in repository you will decide what kind of data source you will ask WCF or straight EF.
Upvotes: 2
Reputation: 19151
That might depend on how you've designed your existing architecture, but basically, you should be able to simply build a new layer on top of what you have, to expose your existing data via web services.
Example: Imagine you use EF to get Apples from the Db. If you then add or use an existing interface with the method GetApplesFromDB()
on top of your existing solution, then your service can call that method when a method GetApples()
in the service itself is called.
The thing you'd have to add here though, are service objects / entities. In other words, if GetApplesFromDB()
returns objects of type Apple
, then you should create a corresponding type, (something like ServiceApple
) in the service, and map from Apple
to ServiceApple
, and return the latter to clients. That way, you can still keep the EF related and Service related stuff somewhat separated.
Upvotes: 3