Created
January 8, 2021 16:52
-
-
Save szymczakk/5d1b56b4e797ad94f4b462e0868872d4 to your computer and use it in GitHub Desktop.
[EF Core] Set column type, if not defined in Column attribute
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void SetColumnTypeIfNoColumnAttribute(ModelBuilder builder, string sqlType, params Type[] types) | |
{ | |
foreach (var property in builder.Model.GetEntityTypes() | |
.SelectMany(t => t.GetProperties()) | |
.Where(p => types.Contains(p.ClrType)) | |
.Where(p => !Attribute.IsDefined(p.PropertyInfo, typeof(ColumnAttribute)))) | |
{ | |
property.SetColumnType(sqlType); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment