views:

25

answers:

1

Hi, I am having a problem filter a query.

I have a Contact and a Tag entities, which are in many to many relationship. Actually in the database, they are 3 different tables,Contacts, Tags and ContactTag table. I would like to filter contacts using the Tag name.

I was trying this filter but it did not work. http://localhost:50143/ContactDataService.svc/Contacts?$filter=Tags/TagName eq 'Tag1'

Am I missing any thing ?

Thanks Thurein

A: 

You are not able to filter on a collection in WCF DataServices at this time. You might consider these alternative solutions:

1 - Query for Tags filtering by TagName, and expand contacts

var q = context.Tags.Expand("Contacts").Where(t => t.TagName == "Tag1");
foreach (var contact in q.ToList().SelectMany(t => t.Contacts).Distinct())
{
    Console.WriteLine(contact.FirstName);
}

2 - Add a service operation that takes a TagName and returns a list of customers that have that tag.

-jeff

Jeff Reed - MSFT

related questions