How do I set default properties for a variable that start with a specific text?

4

Is there any way to set the properties of a variable by default to the initials of variables?

Something like public string obsUsuario { get; set; } , all of which start with obs default to the IsOptional property, (or / and other properties) without having to declare every time for each variable? / p>

modelBuilder.Entity<Usuarios>().Property(prop => prop.obsUsuario).IsOptional();  
    
asked by anonymous 25.11.2016 / 17:11

1 answer

6

Just use a little reflection

modelBuilder.Properties<string>()
        .Where(p => p.Name.StartsWith("descr"))
        .Configure(p => p.IsOptional());
    
25.11.2016 / 17:23