c# - Entity framework add multiple collections to collection with one query -


imagine following scenario... have array contains keywords:

string[] keywords= new string[] { "somekeyword", "otherkeyword", "andanother one"}; 

in database have table news articles. each news article has title, 1 of keywords.

i want news articles contain keywords array 1 query.

at moment iterate keywords , run query fore every item in it:

list<newsarticle> allarticles = new list<newsarticle>();  foreach (var key in keywords) {     var articles = db.newsarticle.findallasync(x => x.title = key).result;     allarticles.add(articles); } 

this works, getting data keywords.length queries. trying data 1 query. following:

var newsarticles = db.newsarticle.all().where(a => keywords.any(k => k.equals(a.title))); 

or

var newsarticles = in db.newsarticles.all()                    join k in keywords on newsarticle.title equals k                    select a; 

is possible 1 query, , if how?

  • note above examples did not work.

please use following linq:

var newsarticles = (from in db.newsarticles                keywords.contains(a.title)                select a).tolist(); 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -