c# - LINQ: How Can I Use Equals in query -


i need use equals method or similar instead of using contains method because want search in database exact values in selecteddevicetypeids array not of it.

 ienumerable<guid> selecteddevicetypeids = devicetypeids     .split(',')     .select( guid.parse )     .asenumerable();  query = query     .where( j =>         j.hospitaldepartments.any( jj =>             jj.units.any( m =>                 m.devices.any( w =>                     selecteddevicetypeids.contains( w.devicetypeid )                 )             )         )     ); 

here full code:

 public httpresponsemessage getavailablehospitalsbyajax(system.guid? directorateofhealthid = null, system.guid? unittypeid = null, string devicetypeids = null)     {          context db = new context();         var query = db.hospitals.asqueryable();          if (devicetypeids != null)         {             ienumerable<guid> selecteddevicetypeids = devicetypeids.split(',').select(guid.parse).asenumerable();             query = query.where(j => j.hospitaldepartments.any(jj => jj.units.any(m => m.devices.any(w => selecteddevicetypeids.contains(w.devicetypeid)))));         }          if (unittypeid != null)         {             query = query.where(j => j.hospitaldepartments.any(www => www.units.any(u => u.unittypeid == unittypeid)));         }          if (directorateofhealthid != null)         {             query = query.where(h => h.directoratehealthid == directorateofhealthid);         }           query = query.where(j => j.hospitaldepartments.any(u => u.units.any(d => d.devices.any(s => s.status == enums.devicestatus.free)))         && j.hospitaldepartments.any(hd => hd.units.any(u => u.beds.any(b => b.status == enums.bedstatus.free))));           var list = query.tolist();         return request.createresponse(httpstatuscode.ok, list);     } 

ef6 supports sql in operator if foo in foo.contains( ) ilist<t>, example, linq:

int32[] desired = new int32[] { 1, 2, 3, 4 };  iqueryable<item> itemsquery = db.items.where( item => desired.contains( item.somevalue ) ); 

...will converted this:

select item.* items somevalue in ( 1, 2, 3, 4 ) 

i'm not entirely on specifics, think if convert selecteddevicetypeids iqueryable<guid> guid[] (or @ least ilist<guid>) ef generate in query you.


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -