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 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           = 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);
        }