c# - Where clause causing cannot compare elements error -


i have 2 tables, doctors , doctorshifts, relation between 2 table one(doctor) many(doctorshifts).

in doctorshifts saved days of week each doctor work on.

what need display list of doctors work today, tried following expression not work :

iqueryable<doctor> todaydoctorsquery = _context.doctors.where(s => s.doctorshifts.where(s2 => s2.dayoftheweek == _todaynumber) != null); 

the error :

cannot compare elements of type 'system.collections.generic.ienumerable`1[[medcare_software.edm.doctorshift, medcare-software, version=1.0.0.0, culture=neutral, publickeytoken=null]]'. primitive types, enumeration types , entity types supported."}

how can list of doctor works today?

the inner clause returns ienumerable<doctorshift> can't compared null.

anyway, you're better off using any in:

var todaydoctorsquery = _context.doctors.where(     s=> s.doctorshifts.any(s2 => s2.dayoftheweek == _todaynumber)); 

and make sure dayoftheweek , _todaynumber same type.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -