ServiceStack Entities Id field name

穿精又带淫゛_ 提交于 2019-12-05 00:13:18

问题


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);

回答1:


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.



来源:https://stackoverflow.com/questions/12329788/servicestack-entities-id-field-name

工具导航Map

JSON相关