internal static byte[] Collapse(byte[] existingData, string entityName, PropertyBase property)
        {
            byte[] result;
            using (MemoryStream memoryStream = new MemoryStream())
            {
                if (existingData != null && existingData.Length > 0)
                {
                    memoryStream.Write(existingData, 0, existingData.Length);
                }
                SqlPropertyDefinition collapsedPropertyByName = MessageTraceCollapsedProperty.GetCollapsedPropertyByName(entityName, property.PropertyName);
                switch (collapsedPropertyByName.Type)
                {
                case SqlPropertyTypes.Int:
                    if (property.PropertyValueInteger != null)
                    {
                        MessageTraceCollapsedProperty.SavePrimitiveValueToStream(memoryStream, typeof(int), collapsedPropertyByName.PropertyId);
                        MessageTraceCollapsedProperty.SavePrimitiveValueToStream(memoryStream, typeof(int), property.PropertyValueInteger.Value);
                    }
                    break;

                case SqlPropertyTypes.String:
                    if (!string.IsNullOrEmpty(property.PropertyValueString))
                    {
                        MessageTraceCollapsedProperty.SavePrimitiveValueToStream(memoryStream, typeof(int), collapsedPropertyByName.PropertyId);
                        MessageTraceCollapsedProperty.SavePrimitiveValueToStream(memoryStream, typeof(string), property.PropertyValueString);
                    }
                    break;

                case SqlPropertyTypes.DateTime:
                    if (property.PropertyValueDatetime != null)
                    {
                        MessageTraceCollapsedProperty.SavePrimitiveValueToStream(memoryStream, typeof(int), collapsedPropertyByName.PropertyId);
                        MessageTraceCollapsedProperty.SavePrimitiveValueToStream(memoryStream, typeof(DateTime), property.PropertyValueDatetime.Value);
                    }
                    break;

                case SqlPropertyTypes.Decimal:
                    if (property.PropertyValueDecimal != null)
                    {
                        MessageTraceCollapsedProperty.SavePrimitiveValueToStream(memoryStream, typeof(int), collapsedPropertyByName.PropertyId);
                        MessageTraceCollapsedProperty.SavePrimitiveValueToStream(memoryStream, typeof(decimal), property.PropertyValueDecimal.Value);
                    }
                    break;

                case SqlPropertyTypes.Blob:
                    if (!string.IsNullOrEmpty(property.PropertyValueBlob.Value))
                    {
                        MessageTraceCollapsedProperty.SavePrimitiveValueToStream(memoryStream, typeof(int), collapsedPropertyByName.PropertyId);
                        MessageTraceCollapsedProperty.SavePrimitiveValueToStream(memoryStream, typeof(string), property.PropertyValueBlob.Value);
                    }
                    break;

                case SqlPropertyTypes.Boolean:
                    if (property.PropertyValueBit != null)
                    {
                        MessageTraceCollapsedProperty.SavePrimitiveValueToStream(memoryStream, typeof(int), collapsedPropertyByName.PropertyId);
                        MessageTraceCollapsedProperty.SavePrimitiveValueToStream(memoryStream, typeof(bool), property.PropertyValueBit.Value);
                    }
                    break;

                case SqlPropertyTypes.Guid:
                    if (property.PropertyValueGuid != Guid.Empty)
                    {
                        MessageTraceCollapsedProperty.SavePrimitiveValueToStream(memoryStream, typeof(int), collapsedPropertyByName.PropertyId);
                        MessageTraceCollapsedProperty.SavePrimitiveValueToStream(memoryStream, typeof(Guid), property.PropertyValueGuid);
                    }
                    break;

                case SqlPropertyTypes.Long:
                    if (property.PropertyValueLong != null)
                    {
                        MessageTraceCollapsedProperty.SavePrimitiveValueToStream(memoryStream, typeof(int), collapsedPropertyByName.PropertyId);
                        MessageTraceCollapsedProperty.SavePrimitiveValueToStream(memoryStream, typeof(long), property.PropertyValueLong.Value);
                    }
                    break;

                default:
                    throw new InvalidOperationException(string.Format("Property type {0} is not supported for MessageTraceCollapsedProperty.", collapsedPropertyByName.Type));
                }
                result = memoryStream.ToArray();
            }
            return(result);
        }
 internal static bool IsCollapsableProperty(string entityName, string propertyName)
 {
     return(MessageTraceCollapsedProperty.GetCollapsedPropertyByName(entityName, propertyName) != null);
 }