private void Insert(DatabaseObject obj)
        {
            if (!obj.NewlyCreated)
            {
                throw new InvalidOperationException("Insert of object not newly created.");
            }

            obj.Validate();

            var columns   = string.Join(", ", obj.Fields.Select(f => f.ColumnName));
            var variables = string.Join(", ", obj.Fields.Select(f => f.VariableName));

            using (var command = Command("INSERT INTO {0} ({1}) VALUES ({2})", TableName(obj.GetType()), columns, variables))
            {
                foreach (var f in obj.Fields)
                {
                    f.AddValue(command);
                }

                command.ExecuteNonQuery();
            }

            obj.Updated();
        }
 public abstract void AssignLoad(DatabaseObject obj);
Exemple #3
0
 public MultiLanguageStringField(DatabaseObject obj, string columnName)
     : base(obj, columnName, false)
 {
     _value = new MultiLanguageString();
 }
Exemple #4
0
 public StringListField(DatabaseObject obj, string columnName, AllowStringType allowType = AllowStringType.SimpleText)
     : base(obj, columnName, false)
 {
     AllowType = allowType;
     _value    = new List <string>();
 }
Exemple #5
0
 protected ValueField(DatabaseObject obj, string columnName, bool nullable)
     : base(obj, columnName, nullable)
 {
 }
Exemple #6
0
 public EnumNullField(DatabaseObject obj, string columnName, Func <T, Translator, string> translate)
     : base(obj, columnName, true)
 {
     _value     = null;
     _translate = translate;
 }
Exemple #7
0
 public GuidIdPrimaryKeyField(DatabaseObject obj, Guid id)
     : base(obj, "id", id)
 {
 }
Exemple #8
0
 public EnumField(DatabaseObject obj, string columnName, T defaultValue, Func <T, Translator, string> translate)
     : base(obj, columnName, false)
 {
     _value     = defaultValue;
     _translate = translate;
 }
Exemple #9
0
 protected Field(DatabaseObject obj, string columnName, bool nullable)
 {
     ColumnName = columnName;
     Nullable   = nullable;
     obj.Fields.Add(this);
 }
Exemple #10
0
 public ReadOnlyField(DatabaseObject obj, string columnName, T defaultValue)
     : base(obj, columnName, false)
 {
     _value = defaultValue;
 }
Exemple #11
0
 public FieldClass(DatabaseObject obj, string columnName, bool nullable)
     : base(obj, columnName, nullable)
 {
     _value = null;
 }
Exemple #12
0
 public FieldNull(DatabaseObject obj, string columnName)
     : base(obj, columnName, true)
 {
     _value = null;
 }
Exemple #13
0
 public ProtoField(DatabaseObject obj, string columnName, bool nullable)
     : base(obj, columnName, nullable)
 {
 }