In my web api 2 project, if I want to use the OData library (which looks amazing and very tempting) for queries on some properties, this would make the client side know the exact properties of my database models. Is this a good practice? Is there any way to avoid this denouement?
For the following models:
public class LetterEntity { public int Id {get; set;} public string Title {get; set;} public string Content {get; set;} public string Source {get; set;} public DateTime SendingTime {get; set;} public string AnotherWierdString {get; set; ... } public class LetterDTO { public int Id {get; set;} public string Title {get; set;} public string LetterContent {get; set;} public string Source {get; set;} public DateTime SendingTime {get; set;} } public class LetterInsideFolderDTO { public string Title {get; set;} public string Source {get; set;} } public class LettersController : ApiController {
Due to the fact that at the moment I take the Entity model directly in the client request, there is a strong connection between the clients and the server. For example, if I want to query and get all the letters that have "abc" inside the Content field, I need to go to the following:
api/letters/?$filter=contains(Content,'abc')
If tomorrow I decide to change this property from "Content" to "LetterContent", all client codes will be violated.
How can I surpass him?
Thanks!
EDIT:
Please give me a specific example, I donβt understand what HATEOAS is (if this helps me solve this problem), How can the documentation service help me? Does it still force customers to change their code if I want to change my EDM models?
source share