设为首页 加入收藏

TOP

Entity Framework工具POCO Code First Generator的使用(七)
2017-10-10 13:49:37 】 浏览:10054
Tags:Entity Framework 工具 POCO Code First Generator 使用
suppress the generation of the return model, and instead return the entity.
// Example: Proc name Return this entity type instead //StoredProcedureReturnTypes.Add("SalesByYear", "SummaryOfSalesByYear"); // Callbacks ********************************************************************************************************************** // This method will be called right before we write the POCO header. Action<Table> WritePocoClassAttributes = t => { if (UseDataAnnotations) { foreach (var dataAnnotation in t.DataAnnotations) { WriteLine(" [" + dataAnnotation + "]"); } } // if(t.ClassName.StartsWith("Order")) // WriteLine(" [SomeAttribute]"); }; // Writes optional base classes Func<Table, string> WritePocoBaseClasses = t => { //if (t.ClassName == "User") // return ": IdentityUser<int, CustomUserLogin, CustomUserRole, CustomUserClaim>"; // Or use the maker class to dynamically build more complex definitions /* Example: var r = new BaseClassMaker("POCO.Sample.Data.MetaModelObject"); r.AddInterface("POCO.Sample.Data.IObjectWithTableName"); r.AddInterface("POCO.Sample.Data.IObjectWithId", t.Columns.Any(x => x.IsPrimaryKey && !x.IsNullable && x.NameHumanCase.Equals("Id", StringComparison.InvariantCultureIgnoreCase) && x.PropertyType == "long")); r.AddInterface("POCO.Sample.Data.IObjectWithUserId", t.Columns.Any(x => !x.IsPrimaryKey && !x.IsNullable && x.NameHumanCase.Equals("UserId", StringComparison.InvariantCultureIgnoreCase) && x.PropertyType == "long")); return r.ToString(); */ return ""; }; // Writes any boilerplate stuff Action<Table> WritePocoBaseClassBody = t => { // Do nothing by default // Example: // WriteLine(" // " + t.ClassName); }; Func<Column, string> WritePocoColumn = c => { bool commentWritten = false; if((IncludeExtendedPropertyComments == CommentsStyle.InSummaryBlock || IncludeComments == CommentsStyle.InSummaryBlock) && !string.IsNullOrEmpty(c.SummaryComments)) { WriteLine(string.Empty); WriteLine(" ///<summary>"); WriteLine(" /// {0}", System.Security.SecurityElement.Escape(c.SummaryComments)); WriteLine(" ///</summary>"); commentWritten = true; } if (UseDataAnnotations) { if(c.Ordinal > 1 && !commentWritten) WriteLine(string.Empty); // Leave a blank line before the next property foreach (var dataAnnotation in c.DataAnnotations) { WriteLine(" [" + dataAnnotation + "]"); } } // Example of adding a [Required] data annotation attribute to all non-null fields //if (!c.IsNullable) // return " [System.ComponentModel.DataAnnotations.Required] " + c.Entity; return " " + c.Entity; }; ForeignKeyFilter = (ForeignKey fk) => { // Return null to exclude this foreign key, or set IncludeReverseNavigation = false // to include the foreign key but not generate reverse navigation properties. // Example, to exclude all foreign keys for the Categories table, use: // if (fk.PkTableName == "Categories") // return null; // Example, to exclude reverse navigation properties for t
首页 上一页 4 5 6 7 8 9 下一页 尾页 7/9/9
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇asp.net MVC 上传文件 System.Web.. 下一篇Wpf TemplateBinding

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目