private void loadEntityKeyField(IEntityField _attribute, PropertyInfo _property) { EntityKeyFieldAttribute _featureAttribute = (EntityKeyFieldAttribute)_attribute; _modelProperties.Add(new ModelProperty(_property, _featureAttribute)); _modelAttributes[_modelo.GetType().Name + "." + _property.Name] = _featureAttribute.FieldName; _KeyField = _attribute.FieldName; //TODO: Incluir validação para lançar exceção caso não tenha entity key field }
public void Save(BaseModel BaseModel) { OracleCommand _Command; string _dml = "INSERT INTO {0}({1}) VALUES({2})"; string _fields = "", _values = ""; foreach (ModelProperty _property in BaseModel.ModelProperties) { _fields += _property.Attribute.FieldName + ","; if (_property.Attribute is EntityKeyFieldAttribute) { EntityKeyFieldAttribute _keyField = (EntityKeyFieldAttribute)_property.Attribute; if (String.IsNullOrEmpty(_keyField.Sequence)) { _values += _getFormatedValue(_property.Property.GetValue(BaseModel, null), _property.Attribute.FieldType) + ","; } else { _Command = new OracleCommand(String.Format("SELECT {0} FROM SYS.DUAL", _keyField.Sequence + ".NEXTVAL")); _Command.Connection = _Connection; OracleDataReader _Reader = _Command.ExecuteReader(); if (_Reader.Read()) { _values += _Reader.GetString(0) + ","; } } } else { _values += _getFormatedValue(_property.Property.GetValue(BaseModel, null), _property.Attribute.FieldType) + ","; } } _fields = _fields.Substring(0, _fields.Length - 1); _values = _values.Substring(0, _values.Length - 1); _Command = new OracleCommand(String.Format(_dml, BaseModel.EntityName, _fields, _values)); _Command.Connection = _Connection; try { _Command.ExecuteNonQuery(); } catch (Exception) { throw; } }