-
Book Overview & Buying
-
Table Of Contents
Practical C# Projects with .NET
By :
Let's turn our attention back to that auto.Map statement and explore what it is we're doing there and why we're doing it.
There are a few reasons we're mapping from our EF model to a custom .NET class. While we could return the EF model, doing so ties our responses directly to the structure of our database. This might result in database changes inadvertently changing the results we send back from our API, impacting external callers expecting results in a certain format. Additionally, I like to make an explicit decision about whether each property in the database should be exposed to external callers. For example, our User model has PasswordHash and Salt properties, which are sensitive pieces of information that we explicitly do not wish to return.
To help combat this, we're using response classes to expose data to external callers:
public abstract class CardResponse {
public int Id { get; init; }
public required...