ServiceStack Entities Id field name

2019-03-29 09:12发布

问题:

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.