简体   繁体   中英

How to write such a query SELECT * FROM TABLE WHERE COLUMN LIKE '%“BLABLA”:[%“BLABLA1”%]%' using Entity Framework

We have a database and some table in it. This table has Filters column to store filters, available for items of this table. and we have partial filters from client which we need to compare with database ones. For example:

database filter column value:

"ANIMAL":["DOG", "CAT", "PARROT", "SNAKE"]

and from client we receive:

"ANIMAL":["PARROT"]

In our case client's filter suits us because we have ANIMAL and PARROT in filter column.

So in usual T-SQL it would be written like something like this:

SELECT * FROM TableWithFilters WHERE Filter LIKE '%"ANIMAL":[%"PARROT"%]%'

But I don't know how can i write this using Entity Framework and if it's at least possible?

See this link. I think it will be helpful for you It's a linq query

LIKE query with Entity Framework

or

Like Operator in Entity Framework?

You may have to change this around a bit as I have typed this out in notepad.

You can use LINQ to pull things from a Database, but this will depend on how you are connecting to your database. This method below I connected and used 'ADO Data Entity Model'.

ADOClass _entity = new ADOClass();

var result = (from d in _entity
              where Filter.Contains("PARROT")
              select d).FirstOrDefault();

This may not be 100% correct but its an idea for you to consider.

You use the LIKE operator like below:

LIKE operator in LINQ

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM