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

}

posted on 2011-03-16 12:48 J-Pei 阅读(...) 评论(...) 编辑 收藏

导航

统计