public AttributeTypeCollection Read(EntityType entityType, IEntityTypeRepository entityTypeRepository) { var attributes = new AttributeTypeCollection(); using (SqlConnection sqlConnection = _connectionProvider.GetConnection()) { using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = string.Format("SELECT * FROM hsck.AttributeTypes WHERE EntityTypeId='{0}'", entityType.Id); using (SqlDataReader reader = sqlCommand.ExecuteReader()) { while (reader.Read()) { var dataType = (DataType) Enum.Parse(typeof (DataType), (string) reader["DataType"]); var attributeType = new AttributeType { Id = (int) reader["Id"], Name = (string) reader["Name"], DataType = dataType }; attributes.Add(attributeType); } } } } attributes.Add(_entityAttributeTypeRepository.Read(entityType, entityTypeRepository)); return attributes; }
public void Create(AttributeType attributeType, EntityType onEntity) { if (attributeType.Name == "Id") { return; } if (attributeType is EntityAttributeType) { _entityAttributeTypeRepository.Create((EntityAttributeType) attributeType, onEntity); return; } CreateValueAttribute(attributeType, onEntity); }
public Attribute(string name, AttributeType attributeType) { Name = name; AttributeType = attributeType; }
private void CreateValueAttribute(AttributeType attributeType, EntityType onEntity) { using (SqlConnection sqlConnection = _connectionProvider.GetConnection()) { using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = string.Format("INSERT INTO hsck.AttributeTypes (Name, DataType, EntityTypeId) " + "VALUES ('{0}', '{1}', {2})", attributeType.Name, attributeType.DataType, onEntity.Id); sqlCommand.ExecuteNonQuery(); } using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = string.Format("ALTER TABLE hsco.{0} ADD {1} {2}", onEntity.Name, attributeType.Name, _dataTypeConverter.ToSqlType(attributeType.DataType)); sqlCommand.ExecuteNonQuery(); } } }
public void Update(EntityType entityType, AttributeType attributeType) { }