asp.net MVC EF dynamic query

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 );

}

你可能感兴趣的:(asp.net)