azure - Querying DocumentDB for a list of propertiers using Linq's Select -
using azure's documentdb , .net api, have following method works great retrieving lists of entire documents:
public async task<ienumerable<t>> getitemsasync<t>(expression<func<t, bool>> predicate) { idocumentquery<t> query = _client.createdocumentquery<t>( urifactory.createdocumentcollectionuri(_databaseid, _collection), new feedoptions { maxitemcount = -1 }) .where(predicate) .asdocumentquery(); list<t> results = new list<t>(); while (query.hasmoreresults) { var item = await query.executenextasync<t>(); results.addrange(item); } return results; }
now, don't want return entire document (especially considering documentdb ru pricing model), thought should able add .select projection so:
public async task<list<tresult>> getitemsasync<t, tresult>(expression<func<t, bool>> predicate, expression<func<t, tresult>> select) { idocumentquery<tresult> query = _client.createdocumentquery<t>( urifactory.createdocumentcollectionuri(_databaseid, _collection), new feedoptions { maxitemcount = -1 }) .where(predicate) .select(select) .asdocumentquery(); list<tresult> results = new list<tresult>(); while (query.hasmoreresults) { var item = await query.executenextasync<tresult>(); results.addrange(item); } return results; }
usage:
var rez = await _docs.getitemsasync<apolloassetdoc, guid?>(x => x.myval == 5, x => x.id);
but second method return 0 results. i'm barking wrong tree.
any idea correct way return list of either dynamic objects queries more 1 property selected (eg "select d.id, d.myval items d d.doctype=0"
)or simple list single property selected (eg "select d.id items d d.doctype=0"
)?
i repro issue, if there no [jsonproperty(propertyname = "id")]
id property in entity class. if not included, please have try use following code:
public class apolloassetdoc { [jsonproperty(propertyname = "id")] public guid id { get; set; } public string myval { get; set; } }
note: field case sensitive.
Comments
Post a Comment