Вопрос

How do I change the serialization method for Guids in OrmLite.MySql for ServiceStack 4?

Version 3 with MySQL stored Guids as text without dashes, and likewise didn't use dashes for comparisons.

After upgrading ServiceStack 4, all my look ups return no data. In the MySQL log, the queries sent by OrmLite now include dashes and that's why there's no matches. I need to set it back to the previous behaviour.

I have customized serialization settings as follows. Do they now apply for OrmLite too as well as DTOs?

    void CustomSerializationSettings()
    {
        ServiceStack.Text.JsConfig<Guid>.SerializeFn = guid => guid.ToString();
        ServiceStack.Text.JsConfig<Guid?>.SerializeFn = guid => guid.HasValue ? guid.ToString() : string.Empty;
        ServiceStack.Text.JsConfig.IncludeNullValues = true;
        ServiceStack.Text.JsConfig.DateHandler = ServiceStack.Text.DateHandler.ISO8601;
        ServiceStack.Text.JsConfig<DateTime>.SerializeFn = DateTimeSerialising.SerialiseDate; 
        ServiceStack.Text.JsConfig<DateTime>.DeSerializeFn = DateTimeSerialising.DeserialiseDate; 
        ServiceStack.Text.JsConfig<DateTime?>.SerializeFn = DateTimeSerialising.SerialiseDateN; 
        ServiceStack.Text.JsConfig<DateTime?>.DeSerializeFn = DateTimeSerialising.DeserialiseDateN; 
    }
Это было полезно?

Решение

This was a breaking change in v4.09 where MySql and Sqlite now treats Guids as CHAR(36), where special casing of Guids was removed for MySQL and Sqlite providers so that the same SQL LINQ expression could work across all providers.

As inferred from the namespace ServiceStack.Text.JsConfig only applies to text serialization, not OrmLite. There's no easy override other than to use a custom MySqlDialectProvider that overrides OrmLite's MySqlDialectProvider to add the special-casing back in. The recommendation however is to upgrade data to use the new (natural) Guid.ToString() format;

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top