新聞中心
在向大家詳細(xì)介紹Linq數(shù)據(jù)和對象之前,首先讓大家了解下linq就主要是解決數(shù)據(jù)不等對象而產(chǎn)生,然后全面介紹Linq數(shù)據(jù)和對象。

創(chuàng)新互聯(lián)服務(wù)項目包括金壇網(wǎng)站建設(shè)、金壇網(wǎng)站制作、金壇網(wǎng)頁制作以及金壇網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,金壇網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到金壇省份的部分城市,未來相信會繼續(xù)擴大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
大家知道在開發(fā)數(shù)據(jù)時,數(shù)據(jù)一般是關(guān)系型數(shù)據(jù),然而數(shù)據(jù)和對象是什么關(guān)系?linq就主要是解決數(shù)據(jù)不等對象而產(chǎn)生。有了Linq數(shù)據(jù)和對象之間就可以有一個一一對應(yīng)的關(guān)系了。而且這些是可以根據(jù)數(shù)據(jù)庫生成這種影射的代碼,也可以根據(jù)影射代碼生成數(shù)據(jù)庫。就是說,數(shù)據(jù)庫和影射代碼實現(xiàn)了相互轉(zhuǎn)化。
先添加Linq to SQL 類,命名為Northwind.dbml,然后再該類添加一數(shù)據(jù)表Customers
從圖的Northwind.designer.cs文件可以看到
- [System.Data.Linq.Mapping.DatabaseAttribute(Name="Northwind")]
- public partial class NorthwindDataContext : System.Data.Linq.DataContext
- {
- [Table(Name="dbo.Customers")]
- public partial class Customers : INotifyPropertyChanging, INotifyPropertyChanged
- {
- private static PropertyChangingEventArgs
emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);- private string _CustomerID;
可以看到NorthwindDataContext是必須從DataContext 類繼承,這樣就獲得Linq的支持。
- private void Form1_Load(object sender, EventArgs e)
- {
- NorthwindDataContext db = new NorthwindDataContext();
- var c = from p in db.Customers
- select p;
- dataGridView1.DataSource = c;
- }
運行效果圖:
以上介紹Linq數(shù)據(jù)和對象
網(wǎng)站欄目:Linq數(shù)據(jù)和對象淺談
鏈接URL:http://m.5511xx.com/article/copoijh.html


咨詢
建站咨詢
