Пример #1
0
        private void EnsureEntityMappingsAreRegistered <TEntity>()
            where TEntity : RedisearchSerializable <TEntity>, new()
        {
            var schemaMetadata = SchemaMetadata <TEntity> .GetSchemaMetadata();

            if (!RedisMapper.IsRegisteredType <TEntity>())
            {
                try
                {
                    RedisMapper.RegisterType <TEntity>(schemaMetadata.Properties.Where(p => !p.IsIgnored).Select(p => p.PropertyName).ToArray());
                }
                catch (Exception ex)
                {
                    throw new ArgumentException($"Entity type cannot be serialized: {typeof(TEntity)}", ex);
                }
            }
        }
Пример #2
0
 public TEntity Deserialize <TEntity>(Dictionary <string, RedisValue> fields) where TEntity : RedisearchSerializable <TEntity>, new()
 {
     EnsureEntityMappingsAreRegistered <TEntity>();
     return(RedisMapper.FromRedisValues <TEntity>(fields));
 }
Пример #3
0
 public Dictionary <string, RedisValue> Serialize <TEntity>(TEntity entity) where TEntity : RedisearchSerializable <TEntity>, new()
 {
     EnsureEntityMappingsAreRegistered <TEntity>();
     return(RedisMapper.MapToRedisValues(entity));
 }