public static EntityClassDefinition GetEntityClassDefinition(this DapperProject project, ScalarFunction scalarFunction) { var definition = new EntityClassDefinition { Namespaces = { "System" }, Namespace = project.Database.HasDefaultSchema(scalarFunction) ? project.GetEntityLayerNamespace() : project.GetEntityLayerNamespace(scalarFunction.Schema), AccessModifier = AccessModifier.Public, Name = scalarFunction.GetEntityName(), Constructors = { new ClassConstructorDefinition(AccessModifier.Public) } }; if (!string.IsNullOrEmpty(scalarFunction.Description)) { definition.Documentation.Summary = scalarFunction.Description; } var selection = project.GetSelection(scalarFunction); definition.Implements.Add("IEntity"); if (selection.Settings.SimplifyDataTypes) { definition.SimplifyDataTypes(); } return(definition); }
public void TestProjectSelectionScope() { // Arrange // Import database var database = SqlServerDatabaseFactory .Import(SqlServerDatabaseFactory.GetLogger(), "server=(local);database=OnLineStore;integrated security=yes;", "dbo.sysdiagrams"); // Create instance of Entity Framework Core project var project = new DapperProject { Name = "OnLineStore", Database = database, OutputDirectory = "C:\\Temp\\CatFactory.Dapper\\OnLineStore.Core" }; // Act // Apply settings for Entity Framework Core project project.GlobalSelection(settings => { settings.ForceOverwrite = true; }); project.Selection("Sales.OrderHeader", settings => settings.UseStringBuilderForQueries = false); var orderHeader = database.FindTable("Sales.OrderHeader"); var selectionForOrder = project.GetSelection(orderHeader); // Assert Assert.True(project.Selections.Count == 2); Assert.True(project.GlobalSelection().Settings.UseStringBuilderForQueries == true); Assert.True(selectionForOrder.Settings.UseStringBuilderForQueries == false); }
public static EntityClassDefinition GetEntityClassDefinition(this DapperProject project, IView view) { var definition = new EntityClassDefinition { Namespaces = { "System" }, Namespace = project.Database.HasDefaultSchema(view) ? project.GetEntityLayerNamespace() : project.GetEntityLayerNamespace(view.Schema), AccessModifier = AccessModifier.Public, Name = project.GetEntityName(view) }; definition.Constructors.Add(new ClassConstructorDefinition(AccessModifier.Public)); if (!string.IsNullOrEmpty(view.Description)) { definition.Documentation.Summary = view.Description; } var selection = project.GetSelection(view); foreach (var column in view.Columns) { var propertyType = project.Database.ResolveDatabaseType(column); var propertyName = project.GetPropertyName(view, column); if (selection.Settings.UseAutomaticPropertiesForEntities) { definition.Properties.Add(new PropertyDefinition { AccessModifier = AccessModifier.Public, Type = project.Database.ResolveDatabaseType(column), Name = project.GetPropertyName(view, column), IsAutomatic = true }); } else { definition.AddPropertyWithField(propertyType, propertyName); } } definition.Implements.Add("IEntity"); if (selection.Settings.SimplifyDataTypes) { definition.SimplifyDataTypes(); } return(definition); }
public static EntityClassDefinition GetEntityClassDefinition(this DapperProject project, ITableFunction tableFunction) { var definition = new EntityClassDefinition { Namespaces = { "System" }, Namespace = project.Database.HasDefaultSchema(tableFunction) ? project.GetEntityLayerNamespace() : project.GetEntityLayerNamespace(tableFunction.Schema), AccessModifier = AccessModifier.Public, Name = project.GetResultName(tableFunction), Constructors = { new ClassConstructorDefinition(AccessModifier.Public) } }; if (!string.IsNullOrEmpty(tableFunction.Description)) { definition.Documentation.Summary = tableFunction.Description; } var selection = project.GetSelection(tableFunction); foreach (var column in tableFunction.Columns) { definition.Properties.Add(new PropertyDefinition { AccessModifier = AccessModifier.Public, Type = project.Database.ResolveDatabaseType(column), Name = project.GetPropertyName(column.Name), IsAutomatic = true }); } definition.Implements.Add("IEntity"); if (selection.Settings.SimplifyDataTypes) { definition.SimplifyDataTypes(); } return(definition); }
public static EntityClassDefinition CreateView(this DapperProject project, IView view) { var definition = new EntityClassDefinition(); definition.Namespaces.Add("System"); definition.Namespace = view.HasDefaultSchema() ? project.GetEntityLayerNamespace() : project.GetEntityLayerNamespace(view.Schema); definition.Name = view.GetEntityName(); definition.Constructors.Add(new ClassConstructorDefinition()); if (!string.IsNullOrEmpty(view.Description)) { definition.Documentation.Summary = view.Description; } var selection = project.GetSelection(view); foreach (var column in view.Columns) { if (selection.Settings.UseAutomaticPropertiesForEntities) { definition.Properties.Add(new PropertyDefinition(project.Database.ResolveType(column), view.GetPropertyNameHack(column))); } else { definition.AddPropertyWithField(project.Database.ResolveType(column), view.GetPropertyNameHack(column)); } } definition.Implements.Add("IEntity"); if (selection.Settings.SimplifyDataTypes) { definition.SimplifyDataTypes(); } return(definition); }
public static EntityClassDefinition CreateEntity(this DapperProject project, ITable table) { var classDefinition = new EntityClassDefinition(); classDefinition.Namespaces.Add("System"); var selection = project.GetSelection(table); if (selection.Settings.EnableDataBindings) { classDefinition.Namespaces.Add("System.ComponentModel"); classDefinition.Implements.Add("INotifyPropertyChanged"); classDefinition.Events.Add(new EventDefinition("PropertyChangedEventHandler", "PropertyChanged")); } classDefinition.Namespace = table.HasDefaultSchema() ? project.GetEntityLayerNamespace() : project.GetEntityLayerNamespace(table.Schema); classDefinition.Name = table.GetEntityName(); classDefinition.Constructors.Add(new ClassConstructorDefinition()); if (table.PrimaryKey != null && table.PrimaryKey.Key.Count == 1) { var column = table.GetColumnsFromConstraint(table.PrimaryKey).First(); classDefinition.Constructors.Add(new ClassConstructorDefinition(new ParameterDefinition(project.Database.ResolveType(column), column.GetParameterName())) { Lines = new List <ILine> { new CodeLine("{0} = {1};", column.GetPropertyName(), column.GetParameterName()) } }); } if (!string.IsNullOrEmpty(table.Description)) { classDefinition.Documentation.Summary = table.Description; } foreach (var column in table.Columns) { if (selection.Settings.EnableDataBindings) { classDefinition.AddViewModelProperty(project.Database.ResolveType(column), table.GetPropertyNameHack(column)); } else { if (selection.Settings.UseAutomaticPropertiesForEntities) { classDefinition.Properties.Add(new PropertyDefinition(project.Database.ResolveType(column), table.GetPropertyNameHack(column))); } else { classDefinition.AddPropertyWithField(project.Database.ResolveType(column), table.GetPropertyNameHack(column)); } } } classDefinition.Implements.Add("IEntity"); if (selection.Settings.SimplifyDataTypes) { classDefinition.SimplifyDataTypes(); } return(classDefinition); }
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); }