I have the following situation:
An “Conversations” entity/table which has multiple Tags associated to it.
Tag is also an entity/table – the key/id is tagName (a string).
On the client side (javascript) I work with arrays of string when dealing with Tags.
Now I want want to retrieve all the conversations that have all given tags.
The input is an array of strings and the output should be a collection of Conversations
I’ve tried:
var filterTags = new List<EFModels.Tag>();
foreach (var tagName in tags)
{
filterTags.Add(new EFModels.Tag() { Name = tagName});
}
var conversations = from c in context.Conversations where !c.Tags.Except(filterTags).Any() select c ;
The problem with this is: Unable to create a constant value of type 'EFModels.Tag'. Only primitive types or enumeration types are supported in this context – which makes sense.
Now how can I do my select? What’s the best approach? (I still want to use linq and not write the sql select)
You can project c.Tags to tag name.
I guess it will look like that
Where filterTags is the list of strings containing the names of the tags