Open DeveloperLookBook opened 5 years ago
See the following sample for a write-only property. I'm not sure this scenario is widely-used enough so as to justify being mentioned in our main docs (@ajcvickers?) - every added bit makes the docs longer and heavier.
public class BlogContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseSqlServer(...);
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Blog>()
.Property("WriteOnlyProperty")
.HasField("_writeOnlyField");
}
}
public class Blog
{
private string _writeOnlyField;
public int Id { get; set; }
public string WriteOnlyProperty
{
set => _writeOnlyField = value;
}
}
@roji Variations on this theme are not uncommon. I think it's worth documenting some of the patterns that work and the limitations that they have. It's not high priority though.
Please, show how to configure model properties that have setter only.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.