c# - ServiceStack.Redis search lists with entity property instead of ID -


i trying use redis cache mvc application through servicestack.redis.

redis work key field (default id). have following classes

[datacontract] public partial class author_book {     public author_book() { }     public author_book(int id, string title, int authorid)     {         this.id = id;         this.title = title;         this.authorid = authorid;     }      [datamember]     public int id { get; set; }     [datamember]     public int authorid { get; set; }     [datamember]     public string title { get; set; }      public virtual author author { get; set; } }  [datacontract] public partial class author {     public author()     {         this.author_book = new hashset<author_book>();     }      public author(int id, string name)     {         this.id = id;         this.name = name;         this.author_book = new hashset<author_book>();     }      [datamember]     public int id { get; set; }     [datamember]     public string name { get; set; }      [datamember]     public virtual icollection<author_book> author_book { get; set; } } 

and following function test

    public static void listtest()     {         // configure redis use authorid id field author_book entities         servicestack.modelconfig<author_book>.id(x => x.authorid);          pooledredisclientmanager redismanager = new pooledredisclientmanager("localhost:6379");          author auth = new author(1, "author-1");         author auth2 = new author(2, "author-2");          author_book ab1 = new author_book(1, "book-1", 1);         author_book ab2 = new author_book(2, "book-2", 2);         author_book ab3 = new author_book(3, "book-3", 2);          ilist<author_book> retlist;          using(iredisclient rc = redismanager.getclient())         {             // store authors             rc.store<author>(auth);             rc.store<author>(auth2);              // store author books             rc.store<author_book>(ab1);             rc.store<author_book>(ab2);             rc.store<author_book>(ab3);              // data redis             list<int> ids = new list<int>();             ids.add(2);             retlist = rc.getbyids<author_book>(ids);         }          foreach(author_book ab in retlist)         {             console.writeline(ab.title);         }         console.read();     } 

what trying here is,

  1. instead of using id, configured redis use authorid key field author_book entity.
  2. trying list of books of author.id=2

the problem is, giving me book-3, expected result book-2 , book-3.

i guess rc.store<author_book>(ab3); overwriting previous record ab2 , ab3 both have same authorid.

how achieve it?

i want store separate lists of entities instead of graph later can updated/deleted individually.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -