Yehia A.Salam
Yehia A.Salam

Reputation: 2028

Another Model for the API

I\m using WebAPI in ASP.net MVC 4.5, and I was wondering what is the best practice when dealing the db entities, should I create another Model (you can call it API model or Service model) that deals with the API, pretty much the same way you create a View model to deal with the razor view, or just communicate directly with the db using the EF entities.

Upvotes: 1

Views: 46

Answers (1)

JackPoint
JackPoint

Reputation: 4111

When it's a public API, I think its better to create extra Web API entities (Models in MVC). You can write a method to map the db entities to Web API entities. When you create extra entities your sure the public side of your API doesn't change when you change database entities.

Upvotes: 2

Related Questions