Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServiceStack Entities Id field name

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);
like image 818
Sergey Zhukov Avatar asked Sep 08 '12 10:09

Sergey Zhukov


1 Answers

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.

like image 171
mythz Avatar answered Sep 24 '22 05:09

mythz