ServiceStack实体标识字段名称 [英] ServiceStack Entities Id field name

查看:199
本文介绍了ServiceStack实体标识字段名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ServiceStack并希望将对象存储为Redis中的哈希,并通过id访问其部分(字段),而无需序列化整个对象,所以我有一个问题:


  1. 有没有办法使用其他属性,然后使用Id来标记id字段? I
    使用命名约定,其中id字段被命名为class

    name + Id​​。所以在User类中将会有UserId id字段,在

    Itemclass ItemId等等中。


  2. 是一种更新属性的方法在对象
    中没有将整个对象序列化为散列值而没有低级别的
    使用Redis的散列命令进行操作?例如,通过使用
    某种类型的lambda表达式。


 

  User user = client.GetById(userId); 
user.Name =新名称;
client.Update< User>(user,u => u.Name);


解决方案

是的,您可以使用 ModelConfig

  ModelConfig< User> .Id(x => x.UserId); 
ModelConfig< Item> .Id(x => x.ItemId);

在使用RedisClient之前,需要在启动时配置一次。


I use ServiceStack and would like to store objects as hashes in Redis and get an access to their parts (fields) by ids without serializing whole object, so I have a questions:

  1. Is there a way to use other property then "Id", to mark id field? I am using naming conventions, where id field is named like "class
    name+Id". So in User class there will be UserId id field, in
    Itemclass ItemId and so on.

  2. Is the a way to update properties that were changed in the object without serializing whole object into hash and without low-level manipulations with hash command of Redis? For example, by using some sort of lambdas.

 

User user=client.GetById(userId);
user.Name="New name";
client.Update<User>(user,u=>u.Name);

解决方案

Yes you can override the default using ModelConfig with:

ModelConfig<User>.Id(x => x.UserId);
ModelConfig<Item>.Id(x => x.ItemId);

This needs to be configured once on startup before you use the RedisClient.

这篇关于ServiceStack实体标识字段名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆