c# - How to check data when loop entity framework? -


i use entity framework , have table. data is

code    check   num c1      true    10 c1      false   20 c2      true    15 c1      false   15 c1      true    15 c1      true    20 c2      false   10 

ok, , i'll filter data code = "c1" , found row check = "true" , num = "15". use code follows:

var list = db.productes.where(e=>e.code == c1); var flag=0; foreach (var item in list) {     if (list.select(e => e.check).singleordefault() == true && list.select(e => e.num).singleordefault() == 15)     {         flag = 1;     }     else         flag = 2; } return flag; 

when run it, value of flag 2. think not work.

why not use enumerable any? ref

var flag = db.productes.any(e => e.code == c1 && e.check && e.num == 15) ? 1 : 2; 

the ? conditional operator in c#. read here.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -