c# - Linq query to get data from a specific RavenDB collection not working as expected -
so i'm using ravendb database contains 2 different collections store picture objects documents. first collection named pictures, second named deletedpictures.
in application for, user can delete picture of themselves. deleted picture object put in second collection deletedpictures. i'm doing changing ravendb document metadata:
session.advanced.getmetadatafor(picture)[constants.ravenentityname] = "deletedpictures";
i'm running problems when making queries retrieve documents deletedpictures collection.
currently i'm using 2 functions utilise linq queries retrieve picture documents, 1 retrieving deleted pictures;
public ienumerable<picture> retrievealldeleted() { var alldeletedpictures = session.query<picture>() .asenumerable() .where(p => session.advanced.getmetadatafor(p) .value<string>("raven-entity-name") == "deletedpictures"); return alldeletedpictures; }
and 1 retrieving deleted pictures specific user;
public ienumerable<picture> retrievealldeletedofuser(int userid) { var alldeletedpicturesofuser = session.query<picture>() .where(p => p.owner == userid) .asenumerable() .where(p => session.advanced.getmetadatafor(p) .value<string>("raven-entity-name") == "deletedpictures"); return alldeletedpicturesofuser; }
found out have use .asenumerable() in linq chain otherwise error:
cannot understand how translate value session.advanced.getmetadatafor(p).value("raven-entity-name")
so let's pictures collection contains 2 documents , deletedpictures collection contains 6 documents (pictures same user owner). first function returns empty list, wrong because should return 6 documents. (all deleted pictures)
second function returns list 6 items, 1 seems working fine.
what wrong query(ies)?
changing collection of object isn't supported. need delete , recreate (even if same id used).
Comments
Post a Comment