public static EntityClassDefinition GetEntityClassDefinition(this DapperProject project, ITable table) { var definition = new EntityClassDefinition { Namespaces = { "System" }, Namespace = project.Database.HasDefaultSchema(table) ? project.GetEntityLayerNamespace() : project.GetEntityLayerNamespace(table.Schema), AccessModifier = AccessModifier.Public, Name = project.GetEntityName(table), Constructors = { new ClassConstructorDefinition { AccessModifier = AccessModifier.Public } } }; var selection = project.GetSelection(table); if (selection.Settings.EnableDataBindings) { definition.Namespaces.Add("System.ComponentModel"); definition.Implements.Add("INotifyPropertyChanged"); definition.Events.Add(new EventDefinition(AccessModifier.Public, "PropertyChangedEventHandler", "PropertyChanged")); } if (table.PrimaryKey != null && table.PrimaryKey.Key.Count == 1) { var column = (Column)table.GetColumnsFromConstraint(table.PrimaryKey).First(); definition.Constructors.Add(new ClassConstructorDefinition { AccessModifier = AccessModifier.Public, Parameters = { new ParameterDefinition(project.Database.ResolveDatabaseType(column), project.GetParameterName(column)) }, Lines = { new CodeLine("{0} = {1};", project.GetPropertyName(table, column), project.GetParameterName(column)) } }); } if (!string.IsNullOrEmpty(table.Description)) { definition.Documentation.Summary = table.Description; } foreach (var column in table.Columns) { var propertyType = project.Database.ResolveDatabaseType(column); var propertyName = project.GetPropertyName(table, column); if (selection.Settings.EnableDataBindings) { definition.AddViewModelProperty(propertyType, propertyName); } else { if (selection.Settings.UseAutomaticPropertiesForEntities) { definition.Properties.Add(new PropertyDefinition { AccessModifier = AccessModifier.Public, Type = propertyType, Name = propertyName, IsAutomatic = true }); } else { definition.AddPropertyWithField(propertyType, propertyName); } } } definition.Implements.Add("IEntity"); if (selection.Settings.SimplifyDataTypes) { definition.SimplifyDataTypes(); } return(definition); }