In Ward\'s article \"The Breeze Server: Have It Your Way\":
The typical business application has a minimum of 200 domain model types. 90+% of the ti
You are in good company. Questions like this are stacking up. I hope to provide better guidance "soon".
In the short run (assuming you're a .NET developer), you may find some clues in the DocCode sample. Search for "ProductDto". DocCode doesn't show how you'd save changes to it so I'll have to hold that off until another time.
Your scenario may actually be easy to address.
DbContext
Start by writing a sub-class of your business model's DbContext
. Add to this sub-class an override to your OnModelCreating
and teach it to ignore the User
properties that should not be part of the model.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<User>().Ignore(u => u.whatever);
...
base.OnModelCreating(modelBuilder);
}
Now refer to THIS derived DbContext
when communicating with clients.
Notice that this involves a very small amount of code and is easy to maintain. It doesn't interfere with your use of the base DbContext
which retains full access to all properties of User
.
Follow James Newton King's guidance. Look in particular at IContractResolver
if you don't want to decorate/pollute your User
class with the [JsonIgnore]
attribute. James is the author of JSON.NET.