设为首页 加入收藏

TOP

Entity Framework工具POCO Code First Generator的使用(八)
2017-10-10 13:49:26 】 浏览:4120
Tags:Entity Framework 工具 POCO Code First Generator 使用
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
首页 上一页 5 6 7 8 9 下一页 尾页 8/9/9
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇c# windows开课啦 下一篇winform基础控件总结

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目