Shadow Property
Motivation
Since we can have default behaviors for propertiesSome fields just need to be hide to prevent accidental modification in code-side.
cs
public class Genre
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public DateTime CreatedDateTime { get; set; }
[JsonIgnore]
public ICollection<Movie> Movies { get; set; } = new HashSet<Movie>();
}
builder.Propert<DateTime>("CreatedDateTime") // what name the shadown property should have
.HasDefaultValueSql("now()")
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
Access shadown property
cs
// inside http api
// `genre` is from post
_ = context.Entry(genre).Property("CreatedDateTime").CurrentValue;
1
2
3
2
3