Created
October 4, 2016 23:10
-
-
Save alinapopa/e83a5aacf6d8db5bb10b09169dc036ac to your computer and use it in GitHub Desktop.
EF Core Custom Conventions
This file contains 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
protected override void OnModelCreating(ModelBuilder modelBuilder) | |
{ | |
foreach (var entityType in modelBuilder.Model.GetEntityTypes()) | |
{ | |
foreach (var property in entityType.GetProperties()) | |
{ | |
var columnName = property.SqlServer().ColumnName; | |
if (columnName.Length > 30) | |
{ | |
throw new InvalidOperationException("Column name is greater than 30 characters - " + columnName); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment