private static MethodDefinition GetToRequestModelMethod(AspNetCoreProject project, ITable table)
        {
            var lines = new List <ILine>
            {
                new CodeLine("return new {0}", project.GetRequestName(table)),
                new CodeLine("{")
            };

            var selection = project.EntityFrameworkCoreProject.GetSelection(table);

            var columns = table.Columns.Where(item => item.Name != selection.Settings.ConcurrencyToken).ToList();

            for (var i = 0; i < columns.Count; i++)
            {
                var column = columns[i];

                lines.Add(new CodeLine(1, "{0} = entity.{0}{1}", project.GetPropertyName(table, column), i < columns.Count - 1 ? "," : string.Empty));
            }

            lines.Add(new CodeLine("};"));

            return(new MethodDefinition(project.GetRequestName(table), "ToRequest", new ParameterDefinition(project.EntityFrameworkCoreProject.GetEntityName(table), "entity"))
            {
                AccessModifier = AccessModifier.Public,
                IsStatic = true,
                IsExtension = true,
                Lines = lines
            });
        }
        public static RequestClassDefinition GetRequestClassDefinition(this AspNetCoreProject project, ITable table)
        {
            var definition = new RequestClassDefinition
            {
                Namespaces =
                {
                    "System",
                    "System.ComponentModel.DataAnnotations",
                    project.Database.HasDefaultSchema(table) ? project.GetEntityLayerNamespace() : project.GetEntityLayerNamespace(table.Schema)
                },
                Namespace      = project.GetRequestsNamespace(),
                AccessModifier = AccessModifier.Public,
                Name           = project.GetRequestName(table)
            };

            var selection = project.EntityFrameworkCoreProject.GetSelection(table);

            foreach (var column in table.Columns.Where(item => selection.Settings.ConcurrencyToken != item.Name).ToList())
            {
                var property = new PropertyDefinition(AccessModifier.Public, project.Database.ResolveDatabaseType(column), project.GetPropertyName(table, column))
                {
                    IsAutomatic = true
                };

                if (table.PrimaryKey?.Key.Count > 0 && table.PrimaryKey?.Key.First() == column.Name)
                {
                    property.Attributes.Add(new MetadataAttribute("Key"));
                }

                if (!column.Nullable && table.PrimaryKey?.Key.Count > 0 && table.PrimaryKey?.Key.First() != column.Name)
                {
                    property.Attributes.Add(new MetadataAttribute("Required"));
                }

                if (project.Database.ColumnIsString(column) && column.Length > 0)
                {
                    property.Attributes.Add(new MetadataAttribute("StringLength", column.Length.ToString()));
                }

                definition.Properties.Add(property);
            }

            definition.SimplifyDataTypes();

            return(definition);
        }