ables ending with Type, use: // if (fk.PkTableName.EndsWith("Type")) // fk.IncludeReverseNavigation = false;
return fk; }; ForeignKeyProcessing = (foreignKeys, fkTable, pkTable, anyNullableColumnInForeignKey) => { var foreignKey = foreignKeys.First(); // If using data annotations and to include the [Required] attribute in the foreign key, enable the following //if (!anyNullableColumnInForeignKey) // foreignKey.IncludeRequiredAttribute = true;
return foreignKey; }; ForeignKeyName = (tableName, foreignKey, foreignKeyName, relationship, attempt) => { string fkName; // 5 Attempts to correctly name the foreign key
switch (attempt) { case 1: // Try without appending foreign key name
fkName = tableName; break; case 2: // Only called if foreign key name ends with "id" // Use foreign key name without "id" at end of string
fkName = foreignKeyName.Remove(foreignKeyName.Length-2, 2); break; case 3: // Use foreign key name only
fkName = foreignKeyName; break; case 4: // Use table name and foreign key name
fkName = tableName + "_" + foreignKeyName; break; case 5: // Used in for loop 1 to 99 to append a number to the end
fkName = tableName; break; default: // Give up
fkName = tableName; break; } // Apply custom foreign key renaming rules. Can be useful in applying pluralization. // For example:
/*if (tableName == "Employee" && foreignKey.FkColumn == "ReportsTo") return "Manager"; if (tableName == "Territories" && foreignKey.FkTableName == "EmployeeTerritories") return "Locations"; if (tableName == "Employee" && foreignKey.FkTableName == "Orders" && foreignKey.FkColumn == "EmployeeID") return "ContactPerson"; */
// FK_TableName_FromThisToParentRelationshipName_FromParentToThisChildsRelationshipName // (e.g. FK_CustomerAddress_Customer_Addresses will extract navigation properties "address.Customer" and "customer.Addresses") // Feel free to use and change the following
/*if (foreignKey.ConstraintName.StartsWith("FK_") && foreignKey.ConstraintName.Count(x => x == '_') == 3) { var parts = foreignKey.ConstraintName.Split('_'); if (!string.IsNullOrWhiteSpace(parts[2]) && !string.IsNullOrWhiteSpace(parts[3]) && parts[1] == foreignKey.FkTableName) { if (relationship == Relationship.OneToMany) fkName = parts[3]; else if (relationship == Relationship.ManyToOne) fkName = parts[2]; } }*/
return fkName; }; ForeignKeyAnnotationsProcessing = (Table fkTable, Table pkTable, string propName) => { /* Example: // Each navigation property that is a reference to User are left intact if (pkTable.NameHumanCase.Equals("User") && propName.Equals("User")) return null; // all the others are marked with this attribute return new[] { "System.Runtime.Serialization.IgnoreDataMember" }; */
return null; }; // Return true to include this table in the db context
ConfigurationFilter = (Table t) => { return true; }; // That's it, nothing else to configure *********************************************************************************************** // Read schema
var factory = GetDbProviderFactory(); var tables = LoadTables(factory); var storedProcs = LoadStoredProcs(factory); // Gen |