开发者

ado.net-data-services filer using composite

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开发者_运维百科


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜