internal static IEnumerable <T> Expand <T>(byte[] data, string entityName, Func <T> objectBuilder) where T : PropertyBase
        {
            using (MemoryStream stream = new MemoryStream(data))
            {
                while (stream.Position < stream.Length)
                {
                    long startPosition = stream.Position;
                    int  propertyId    = (int)MessageTraceCollapsedProperty.ReadPrimitiveValueFromStream(stream, typeof(int));
                    SqlPropertyDefinition propertyDefinition = MessageTraceCollapsedProperty.GetCollapsedPropertyById(entityName, propertyId);
                    T property = objectBuilder();
                    property.PropertyName = propertyDefinition.PropertyName;
                    switch (propertyDefinition.Type)
                    {
                    case SqlPropertyTypes.Int:
                        property.PropertyValueInteger = new int?((int)MessageTraceCollapsedProperty.ReadPrimitiveValueFromStream(stream, typeof(int)));
                        break;

                    case SqlPropertyTypes.String:
                        property.PropertyValueString = (string)MessageTraceCollapsedProperty.ReadPrimitiveValueFromStream(stream, typeof(string));
                        break;

                    case SqlPropertyTypes.DateTime:
                        property.PropertyValueDatetime = new DateTime?((DateTime)MessageTraceCollapsedProperty.ReadPrimitiveValueFromStream(stream, typeof(DateTime)));
                        break;

                    case SqlPropertyTypes.Decimal:
                        property.PropertyValueDecimal = new decimal?((decimal)MessageTraceCollapsedProperty.ReadPrimitiveValueFromStream(stream, typeof(decimal)));
                        break;

                    case SqlPropertyTypes.Blob:
                        property.PropertyValueBlob = new BlobType((string)MessageTraceCollapsedProperty.ReadPrimitiveValueFromStream(stream, typeof(string)));
                        break;

                    case SqlPropertyTypes.Boolean:
                        property.PropertyValueBit = new bool?((bool)MessageTraceCollapsedProperty.ReadPrimitiveValueFromStream(stream, typeof(bool)));
                        break;

                    case SqlPropertyTypes.Guid:
                        property.PropertyValueGuid = (Guid)MessageTraceCollapsedProperty.ReadPrimitiveValueFromStream(stream, typeof(Guid));
                        break;

                    case SqlPropertyTypes.Long:
                        property.PropertyValueLong = new long?((long)MessageTraceCollapsedProperty.ReadPrimitiveValueFromStream(stream, typeof(long)));
                        break;

                    default:
                        throw new InvalidOperationException(string.Format("Property type {0} is not supported for MessageTraceCollapsedProperty.", propertyDefinition.Type));
                    }
                    yield return(property);

                    if (stream.Position <= startPosition)
                    {
                        throw new InvalidOperationException("Unable to expand. Stream position is not moving forward.");
                    }
                }
            }
            yield break;
        }