I have the following model to get data from database:
public class CultureResource
{
public string KeyName { get; set; }
public List<Resource> Resources { get; set; }
}
public class Resource
{
public string Value { get; set; }
public string Culture { get; set; }
}
Now my goal is to get data for a list of keys & culture where keys matches with CultureResource.KeyName & culture matches with Resource.Culture. How can I write a linq query on a IQueryable<CultureResource> to get a result of IList<Result> where Result may look like the following:
public class Result
{
public string KeyName {get; set;}
public string Value {get; set;}
}
I have tried the following Linq, but it throws $project or $group does not support {document}. error:
public IDictionary<string, string> GetLocalizedValueList(string[] keys, string culture)
{
// returns IQueryable<CultureResource>
var cultureResources = _repository.GetItems<CultureResource>();
/***** This is the query *********/
var query = from cr in cultureResources
from r in cr.Resources
where keys.Contains(cr.KeyName) && r.Culture == culture
select new { cr.KeyName, r.Value };
var result = query.ToList()
//return some data
}
FYI: my underlying database is mongo