Skip to content

Instantly share code, notes, and snippets.

@alinapopa
Created October 4, 2016 23:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alinapopa/e83a5aacf6d8db5bb10b09169dc036ac to your computer and use it in GitHub Desktop.
Save alinapopa/e83a5aacf6d8db5bb10b09169dc036ac to your computer and use it in GitHub Desktop.
EF Core Custom Conventions
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