I use EntityFramework on my ASP.NET MVC project.
Let’s say I have the entity below:
public class Project
{
public int ProjectID { get; set; }
public string Description { get; set; }
public string Tags { get; set; }
}
Lets say I have the following data in my DB:
ProjectID: 1
Description: "My first element"
Tags: "one, three, five, seven"
ProjectID: 2
Description: "My second element"
Tags: "one, two, three, six"
ProjectID: 3
Description: "My third element"
Tags: "two, three, four"
I would like to return all projects containing a specific number of tags. So for example I would like to get all projects with tags ‘one’ and ‘three’. The list of tags to search for is dynamic and is stored in a variable like this: searchFor = "one, three";.
How can I do?
Thanks.
In controller create your ObjectContext entity object and call its method “Where”
example:
db.Projects.Where(p => p.Tags.indexOf("one") > -1 && p.Tags.indexOf(three) > -1);And send it to the view as list.
example: