Currently, I'm working with an IQueryable() and cannot get part of the query to work. I'm getting a System.ArgumentException with a description that is in the title of this post.
I'll start with the TSQL query that I need but in IQueryable() code:
SELECT w.*,wr.*,c.*
FROM WorldRegion w
JOIN WorldRegionResource wr
ON w.Id = wr.Id
JOIN Culture c
ON wr.CultureId = c.Id
WHERE c.CultureName = 'en-US'
Now I'll break the code:
Here's the Entity structure:
public class WorldRegion
{
public virtual ICollection<WorldRegionResource> WorldRegionResources { get; set; }
}
public class WorldRegionResource
{
public Culture Culture { get; set; }
}
public class Culture
{
public string CultureName { get; set; }
}
Here's a working query (with other expressions removed for brevity), but I need to add a filter to this as this returns ALL available WorldRegionResources for the WorldRegion and I want to return ONE:
IQueryable<WorldRegion> query = repository.Queryable();
query.Include(w => w.WorldRegionResources.Select(wr => wr.Culture));
I need to add a filter:
Where Culture.CultureName == "en-US"
Initially I tried changing the query.Include (which threw the exception):
query.Include(w => w.WorldRegionResources.Where(wr => wr.Culture.CultureName == "en-US"));
I've been searching for a solution, but with no success. I've even tried building an anonymous query:
query.Include(w => w.WorldRegionResources.Select(wr => wr.Culture));
query.Select(w => new
{
WorldRegion = w,
WorldRegionResource = w.WorldRegionResources.Select(wr => new
{
WorldRegionResource = wr,
Culture = wr.Culture.CultureName == "en-US"
})
});
But this produced the same result as the initial query. SQL Server Profiler doesn't even recognize the 'en-US' parameter.
Thank you in advance for your time and any assistance is appreciated,
Ronnie