Linq 動態查詢

來源:互聯網
上載者:User

最近在做項目中用到了LINQ TO SQL,在用的時候感覺很,寫的代碼也少;提高了開發的周期;但是在開發的過程中我們還是碰到很多的東西,由於是第一把LINQ用到項目中,原來是寫個小的DEMO;沒有過多的用到他的優點;

一個MIS項目中都會用到一些進階的查詢功能,但由於是第一次用他很多的還不清楚,在網上找了一下,LINQ也是支援動態查詢的,只不過要把動態查詢內庫單獨下載下來,引用到自己的項目中;這樣才能用;現在看看具體是怎麼用的吧

看看我的文件目錄吧:

第一:你得到網上傳動態查詢庫原始碼,這裡我是把這個原始碼下載後,打成了一個DLL庫,方便以後能用到;

第二:就可以寫查詢的代碼了:

public partial class _Default : System.Web.UI.Page   {       protected void Page_Load(object sender, EventArgs e)       {           CAO.DAL.Student st = new CAO.DAL.Student();           st.AddStudentInfo();           GV.DataSource = st.StudentInfo("StudentName=\"ranting\" and StudnetAge=22");           GV.DataBind();       }   }

DAL層的代碼如下:
public IEnumerable<CAO.Data.Student> StudentInfo()       {           return (from st in db.Student select st);       } public IEnumerable<CAO.Data.Student> StudentInfo(string where)    {           return (db.Student.Where(where));    }就這麼簡單;希望對初學者有所協助;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.