public void Create(EntityAttributeType entityAttributeType, EntityType onEntity) { using (SqlConnection sqlConnection = _connectionProvider.GetConnection()) { using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = string.Format( "INSERT INTO hsck.EntityAttributeTypes (Name, ChildEntityTypeName, ParentEntityTypeName)" + "VALUES ('{0}', '{1}', '{2}')", entityAttributeType.Name, entityAttributeType.OfType.Name, onEntity.Name); sqlCommand.ExecuteNonQuery(); } using (SqlCommand sqlCommand = sqlConnection.CreateCommand()) { sqlCommand.CommandText = string.Format("ALTER TABLE hsco.{0} ADD {1} {2}", onEntity.Name, entityAttributeType.Name, _dataTypeConverter.ToSqlType(DataType.Entity)); sqlCommand.ExecuteNonQuery(); } } }
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.EntityAttributeTypes WHERE ParentEntityTypeName='{0}'", entityType.Name); using (SqlDataReader reader = sqlCommand.ExecuteReader()) { while (reader.Read()) { var entityTypeName = (string) reader["ChildEntityTypeName"]; var attributeName = (string) reader["Name"]; EntityType ofType = entityTypeName == entityType.Name ? entityType : entityTypeRepository.Read(entityTypeName); var entityAttributeType = new EntityAttributeType { Id = (int) reader["Id"], Name = attributeName, OfType = ofType }; attributes.Add(entityAttributeType); } } } } return attributes; }