private static void CreateTableWithOneRecord(SupportsAttribute support, IDatabase db, bool onPrimaryKey) { // add expectation const string expectedContent = "Something"; var expectedTable = new ExpectedTable(string.Format(CultureInfo.InvariantCulture, "Mig4 {0}Identity {1}", onPrimaryKey ? "PK-" : string.Empty, support.DbType), "Id", "Content"); ExpectedTables.Add(expectedTable); expectedTable.Add(1, expectedContent); // create table var table = db.CreateTable(expectedTable.Name); var identityColumn = onPrimaryKey ? table.WithPrimaryKeyColumn("Id", support.DbType).AsIdentity() : table.WithNotNullableColumn("Id", support.DbType).AsIdentity(); if (support.MaximumSize > 0) { identityColumn.OfSize(support.MaximumSize, support.MaximumScale > 0 ? support.MaximumScale : (int?)null); } table.WithNotNullableColumn("Content", DbType.String).OfSize(255); // insert one record to see if Identity works db.Execute(string.Format(CultureInfo.InvariantCulture, @"INSERT INTO ""{0}"" (""{1}"") VALUES ('{2}')", expectedTable.Name, "Content", expectedContent)); }
private void Validate(IProviderMetadata providerMetadata, IEnumerable <SupportsAttribute> supportsAttributes, IEnumerable <UnsupportedMethod> unsupportedMethods, IMigrationReport report, List <ValidationWarning> warningMessages, List <string> errorMessages) { if (!string.IsNullOrEmpty(report.Error)) { errorMessages.Add(string.Format(CultureInfo.InvariantCulture, "Error in migration '{0}': {1}", report.MigrationName, report.Error)); } // check created object name lengths if (providerMetadata.MaximumDbObjectNameLength > 0 && !string.IsNullOrEmpty(report.LongestName) && providerMetadata.MaximumDbObjectNameLength < report.LongestName.Length) { errorMessages.Add(string.Format(CultureInfo.CurrentCulture, "Migration '{0}' contains object names that are longer than what is supported by '{1}' ('{2}': {3}, supported: {4}).", report.MigrationName, providerMetadata.GetPlatform(), report.LongestName, report.LongestName.Length, providerMetadata.MaximumDbObjectNameLength)); } // check used data types foreach (DataType dataType in report.DataTypes) { DbType dbType = dataType.DbType; List <SupportsAttribute> attributes = supportsAttributes.Where(a => a.DbType == dbType).ToList(); if (attributes.Count == 0) { errorMessages.Add(string.Format(CultureInfo.CurrentCulture, "Migration '{0}' uses the data type '{1}' which is not supported by '{2}'.", report.MigrationName, dataType, providerMetadata.GetPlatform())); continue; } // post-condition: the data type is supported // check if OfSize was specified correctly SupportsAttribute attribute = attributes.Find(a => !(a.MaximumSize > 0 ^ dataType.Size.HasValue) && !(a.MaximumScale > 0 ^ dataType.Scale.HasValue)); if (attribute == null) { errorMessages.Add(string.Format(CultureInfo.CurrentCulture, "Migration '{0}' uses the data type '{1}' which is not supported by '{2}'.", report.MigrationName, dataType, providerMetadata.GetPlatform())); continue; } // post-condition: the data type is supported and OfSize was specified with the correct number of parameters // check other properties if (report.PrimaryKeyDataTypes.Contains(dataType) && !attribute.CanBeUsedAsPrimaryKey) { errorMessages.Add(string.Format(CultureInfo.CurrentCulture, "Migration '{0}' uses the data type '{1}' for a primary key which is not supported by '{2}'.", report.MigrationName, dataType, providerMetadata.GetPlatform())); } if (report.IdentityDataTypes.Contains(dataType) && !attribute.CanBeUsedAsIdentity) { errorMessages.Add(string.Format(CultureInfo.CurrentCulture, "Migration '{0}' uses the data type '{1}' for an identity column which is not supported by '{2}'.", report.MigrationName, dataType, providerMetadata.GetPlatform())); } if (attribute.MaximumSize > 0 && dataType.Size > attribute.MaximumSize) { errorMessages.Add(string.Format(CultureInfo.CurrentCulture, "Migration '{0}' uses the data type '{1}' which exceeds the maximum size of {2} supported by '{3}'.", report.MigrationName, dataType, attribute.MaximumSize, providerMetadata.GetPlatform())); } if (attribute.MaximumScale > 0 && dataType.Scale > attribute.MaximumScale) { errorMessages.Add(string.Format(CultureInfo.CurrentCulture, "Migration '{0}' uses the data type '{1}' which exceeds the maximum scale of {2} supported by '{3}'.", report.MigrationName, dataType, attribute.MaximumScale, providerMetadata.GetPlatform())); } if (!string.IsNullOrEmpty(attribute.Warning)) { warningMessages.Add(new ValidationWarning(report.MigrationName, dataType, providerMetadata.GetPlatform(), attribute.Warning)); } if (providerMetadata.InvariantName == "System.Data.Odbc") // ODBC specific warnings { if (dataType.DbType == DbType.Int64) { warningMessages.Add(new ValidationWarning(report.MigrationName, dataType, providerMetadata.GetPlatform(), "Int64 is not supported for DbParameters with ODBC; requires calling ToString to directly inline the value in the CommandText.")); } } } // check used methods foreach (UnsupportedMethod method in unsupportedMethods .Join(report.Methods, um => um.Name, m => m, (um, m) => um)) { errorMessages.Add(string.Format(CultureInfo.CurrentCulture, "Migration '{0}' calls the '{1}' method which is not supported by '{2}': {3}", report.MigrationName, method.Name, providerMetadata.GetPlatform(), method.Message)); } // filter suppressed warnings warningMessages.RemoveAll(WarningIsSuppressed); }