I’m a beginner in using Linq and a lot of it is completely confusing right now.
I downloaded and used the LinqFlickr library from http://linqflickr.codeplex.com. I think however that this is just my lack of understanding about Linq. There isn’t much documentation on the LinqFlickr project for me to go on.
If I run the following code, if the username string is blank, it runs fine and returns photos with a specific tag. But if there is a username in it, it should refine the previous results by specific users, instead it gives me a bunch of random photos.
var photos = (from ph in context.Photos
where
ph.SearchMode == SearchMode.TagsOnly
&& ph.SearchText == tag
&& ph.PhotoSize == PhotoSize.Small
&& ph.Extras == (ExtrasOption.Owner_Name | ExtrasOption.Date_Taken)
select ph);
if (username != "")
{
string personId = (from people in context.Peoples
where
people.Username == username
select people.Id).First();
photos = photos.Where(q => q.NsId == personId) ;
}
photos = photos.Take(10);
I tried using some debugging tools such as LinqPad and MetaLinq but I haven’t been able to solve it with them.
Also, I’m sure my Linq query could be made in one query which would be great, but please explain it so a Linq newbie can understand!
Your query looks fine. My guess would be that this is a bug (or unintuitive by-design behaviour) in Athena where an extra “chained”
whereclause causes the originalwhereclause to be forgotten.Assemble the second query independently (i.e. all the constraints in one big
whereclause) and check that this fixes things. If it does, it’s definitely a bug in the API. You can work around this by using LINQKit to assemble and expand the predicate for thewhereclause dynamically. Here’s how this might look: