lambda:
ids.add( _hahahacontext .hahahamodel .firstordefault( a => //lambda做过滤 a.name == "张宏伟" && a.age== 18 ) .id .tostring() );
linq:
ids.add(( from r in _hahahacontext.hahahamodel // linq 做查询过滤 where (r.name == "张宏伟"&& r.age == 18) select r.id ).firstordefault() .tostring() );
涉及到多表联查的时候,那真的是linq看起来更清晰,而lambda的话可能会把你搞乱。
比如:
viewmodel.fields = new selectlist( _hahahacontext .hahahamodel1 .where( a => _hahahacontext .hahahamodel2 .where( // lambda 过滤和联查都是放到一起的,容易搞乱 b => a.ref_enumid == "-5136816235353979" && b.ref_enumid == "-5136816235353979" && a.state == "1" && a.parent_id == b.id //表关联 && b.showvalue != "欧洲" ) .any() ) .select(a => a.showvalue) .toarray() .prepend("") .distinct() .tolist() .orderby(a => a.tostring()));
但是,linq 中可以用“ join ” 来联查,如同sql语句一样。