public static EntityClassDefinition CreateEntity(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 = table.GetEntityName(), 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("PropertyChangedEventHandler", "PropertyChanged") { AccessModifier = AccessModifier.Public }); } if (table.PrimaryKey != null && table.PrimaryKey.Key.Count == 1) { var column = table.GetColumnsFromConstraint(table.PrimaryKey).First(); definition.Constructors.Add(new ClassConstructorDefinition(AccessModifier.Public, new ParameterDefinition(project.Database.ResolveDatabaseType(column), column.GetParameterName())) { Lines = { new CodeLine("{0} = {1};", project.GetPropertyName(table, column), column.GetParameterName()) } }); } if (!string.IsNullOrEmpty(table.Description)) { definition.Documentation.Summary = table.Description; } foreach (var column in table.Columns) { if (selection.Settings.EnableDataBindings) { definition.AddViewModelProperty(project.Database.ResolveDatabaseType(column), project.GetPropertyName(table, column)); } else { if (selection.Settings.UseAutomaticPropertiesForEntities) { definition.Properties.Add(new PropertyDefinition(AccessModifier.Public, project.Database.ResolveDatabaseType(column), project.GetPropertyName(table, column)) { IsAutomatic = true }); } else { definition.AddPropertyWithField(project.Database.ResolveDatabaseType(column), project.GetPropertyName(table, column)); } } } definition.Implements.Add("IEntity"); if (selection.Settings.SimplifyDataTypes) { definition.SimplifyDataTypes(); } return(definition); }
public static EntityClassDefinition GetEntityClassDefinition(this DapperProject project, StoredProcedure storedProcedure) { var definition = new EntityClassDefinition { Namespaces = { "System" }, Namespace = project.Database.HasDefaultSchema(storedProcedure) ? project.GetEntityLayerNamespace() : project.GetEntityLayerNamespace(storedProcedure.Schema), AccessModifier = AccessModifier.Public, Name = project.GetResultName(storedProcedure), Constructors = { new ClassConstructorDefinition(AccessModifier.Public) } }; foreach (var resultSet in storedProcedure.FirstResultSetsForObject) { var type = project.Database.ResolveDatabaseType(resultSet.SystemTypeName); definition.Properties.Add(new PropertyDefinition { AccessModifier = AccessModifier.Public, Type = type, Name = resultSet.Name, IsAutomatic = true }); } return(definition); }