public virtual IModel ConstructRelationalModel() { var relationalModel = new Entity.Metadata.Model(); foreach (var table in _tables.Values) { relationalModel.AddEntityType(table.Id); } foreach (var tc in _tableColumns.Values) { var entityType = relationalModel.FindEntityType(tc.TableId); if (entityType == null) { _logger.LogWarning( Strings.CannotFindTableForColumn(tc.Id, tc.TableId)); continue; } // IModel will not allow Properties to be created without a Type, so map to CLR type here. // This means if we come across a column with a SQL Server type which we can't map we will ignore it. // Note: foreign key properties appear just like any other property in the relational model. Type clrPropertyType; if (!SqlServerTypeMapping._sqlTypeToClrTypeMap.TryGetValue(tc.DataType, out clrPropertyType)) { _logger.LogWarning( Strings.CannotFindTypeMappingForColumn(tc.Id, tc.DataType)); continue; } if (tc.IsNullable) { clrPropertyType = clrPropertyType.MakeNullable(); } var relationalProperty = entityType.AddProperty(tc.Id, clrPropertyType, shadowProperty: true); _relationalColumnIdToRelationalPropertyMap[tc.Id] = relationalProperty; } return(relationalModel); }