开发者

ado.net-data-services filer using composite

开发者 https://www.devze.com 2022-12-29 07:13 出处:网络
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 t

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

精彩评论

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

关注公众号