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);
public MultiLanguageStringField(DatabaseObject obj, string columnName) : base(obj, columnName, false) { _value = new MultiLanguageString(); }
public StringListField(DatabaseObject obj, string columnName, AllowStringType allowType = AllowStringType.SimpleText) : base(obj, columnName, false) { AllowType = allowType; _value = new List <string>(); }
protected ValueField(DatabaseObject obj, string columnName, bool nullable) : base(obj, columnName, nullable) { }
public EnumNullField(DatabaseObject obj, string columnName, Func <T, Translator, string> translate) : base(obj, columnName, true) { _value = null; _translate = translate; }
public GuidIdPrimaryKeyField(DatabaseObject obj, Guid id) : base(obj, "id", id) { }
public EnumField(DatabaseObject obj, string columnName, T defaultValue, Func <T, Translator, string> translate) : base(obj, columnName, false) { _value = defaultValue; _translate = translate; }
protected Field(DatabaseObject obj, string columnName, bool nullable) { ColumnName = columnName; Nullable = nullable; obj.Fields.Add(this); }
public ReadOnlyField(DatabaseObject obj, string columnName, T defaultValue) : base(obj, columnName, false) { _value = defaultValue; }
public FieldClass(DatabaseObject obj, string columnName, bool nullable) : base(obj, columnName, nullable) { _value = null; }
public FieldNull(DatabaseObject obj, string columnName) : base(obj, columnName, true) { _value = null; }
public ProtoField(DatabaseObject obj, string columnName, bool nullable) : base(obj, columnName, nullable) { }