private void Fix(TableMapping map)
        {
            var cmd = CreateCommand("select * from " + map.TableSource);

            //Add missing columns
            try
            {
                DataTable dt = new DataTable();
                dt.Load(cmd.ExecuteReader(CommandBehavior.SchemaOnly));
                foreach (var col in map.NameForPath.Select((x) => GetElement(map, x)))
                {
                    if (dt.Columns.IndexOf(col.Name) == -1)
                    {
                        Exec("ALTER TABLE " + map.TableSource + " ADD " + col.Name + " " + col.Type);
                    }
                }
            }
            catch
            {
            }

            var cols = from path in map.NameForPath
                       select GetElement(map, path);

            var isMultiplePrimary = cols.Count((x) => x.Primary.Length > 0) > 1;

            string createTable = "CREATE TABLE IF NOT EXISTS " + map.TableSource + "(";

            createTable += string.Join(",", from t in cols select t.Name + " " + t.Type + " " + (isMultiplePrimary ? string.Empty : t.Primary));
            if (isMultiplePrimary)
            {
                createTable += ",PRIMARY KEY(" + string.Join(",", from t in cols where t.Primary.Length > 0 select t.Name) + ")";
            }
            createTable += ")";
            Exec(createTable);
        }
Beispiel #2
0
 public MappingContext(TableMapping table, MappingContext parent) : this(table)
 {
     Parent = parent;
 }
Beispiel #3
0
 public MappingContext(TableMapping table)
 {
     Current = table;
 }