public static Type ResolveUserType(this ColumnDescription columnDescription)
 {
     _ = Check.NotNull(nameof(columnDescription), columnDescription);
     return(columnDescription.UserType switch
     {
         "sql_variant" => typeof(int),
         _ => SqlTypeUtility.GetDataType(columnDescription.UserType, columnDescription.MaxLength),
     });
Example #2
0
        public void AddColumnPrescriptions()
        {
            var fileName = Temporary.GetTempFilePath();
            var project  = CreateProject();

            ValueFactoryManager.Initialize();

            var i = 0;

            foreach (var tableDescription in project.Descriptor.TableDescriptions)
            {
                var tablePrescription = new TablePrescription(tableDescription);

                foreach (var columnDescription in tableDescription.ColumnDescriptions)
                {
                    if (columnDescription.Identity != null || !columnDescription.IsWritable())
                    {
                        continue;
                    }

                    var type = columnDescription.UserType switch
                    {
                        "sql_variant" => typeof(int),
                        _ => SqlTypeUtility.GetDataType(columnDescription.UserType, columnDescription.MaxLength),
                    };

                    var factory = ValueFactoryManager.ValueFactoryInfos.FilterByType(type).FirstOrDefault();
                    Assert.NotNull(factory);
                    var configuration            = factory.Configurator.CreateConfiguration();
                    var valueFactoryPrescription = new ValueFactoryPrescription(factory.Name + i++, factory.Name, configuration);
                    project.Prescriptor.AddValueFactory(valueFactoryPrescription);

                    var columnPrescription = new ColumnPrescription(columnDescription, valueFactoryPrescription, null);
                    tablePrescription.AddColumn(columnPrescription);
                }

                project.Prescriptor.AddTable(tablePrescription);
            }

            ProjectManager.SaveToFile(project, fileName);

            Output.WriteLine(File.ReadAllText(fileName));
            var project2 = ProjectManager.LoadFromFile(fileName);

            IoAssert.AsExpected(project2);
        }