/// <summary>创建实体类</summary> public void Create() { Class = new CodeTypeDeclaration(Name); Class.IsClass = true; Class.IsPartial = true; Class.TypeAttributes = TypeAttributes.Public; Class.AddSummary(Table.Description); // 特性 Class.AddAttribute <SerializableAttribute>(); Class.AddAttribute <DataObjectAttribute>(); if (!Table.Description.IsNullOrWhiteSpace()) { Class.AddAttribute <DescriptionAttribute>(Table.Description); } if (!Table.DisplayName.IsNullOrWhiteSpace() && Table.DisplayName != Table.Name) { Class.AddAttribute <DisplayNameAttribute>(Table.DisplayName); } Class.AddAttribute <CompilerGeneratedAttribute>(); // 索引和关系 if (Table.Indexes != null && Table.Indexes.Count > 0) { foreach (var item in Table.Indexes) { if (item.Columns.Length < 1) { continue; } Class.AddAttribute <BindIndexAttribute>(item.Name, item.Unique, String.Join(",", item.Columns)); } } if (Table.Relations != null && Table.Relations.Count > 0) { foreach (var item in Table.Relations) { Class.AddAttribute <BindRelationAttribute>(item.Column, item.Unique, item.RelationTable, item.RelationColumn); } } // 绑定表 Class.AddAttribute <BindTableAttribute>(Table.TableName, Table.Description, Table.ConnName ?? ConnName, Table.DbType, Table.IsView); // 基类 Class.BaseTypes.Add(BaseType); }