asp.net MVC EF dynamic query

39607 단어 asp.net
Entity FrameWork 4.1
public SearchMyThings( string a, string b, int c )
{
     
var mywidgets = DBContext.DbSet<Widget>();
     
 if( !a.IsNullOrEmpty )
        mywidgets
= mywidgets.Where( w => w.AProperty == a );

     
if( !b.IsNullOrEmpty )
        mywidgets
= mywidgets.Where( w => w.BProperty == b );

     
if( c > 0 )
        mywidgets
= mywidgets.Where( c => c.CProperty == c );

}

좋은 웹페이지 즐겨찾기