欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

Linq中怎么插入數(shù)據(jù)

本篇文章為大家展示了Linq中怎么插入數(shù)據(jù),內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。

讓客戶滿意是我們工作的目標(biāo),不斷超越客戶的期望值來自于我們對這個行業(yè)的熱愛。我們立志把好的技術(shù)通過有效、簡單的方式提供給客戶,將通過不懈努力成為客戶在信息化領(lǐng)域值得信任、有價值的長期合作伙伴,公司提供的服務(wù)項目有:域名注冊、網(wǎng)絡(luò)空間、營銷軟件、網(wǎng)站建設(shè)、燈塔網(wǎng)站維護、網(wǎng)站推廣。

要插入數(shù)據(jù)的表結(jié)構(gòu)是:

create table RSSFeedRight    (    FeedId int Foreign Key (FeedId) References RSSFeed(FeedId) NOT NULL , -- FeedId , UserId int Foreign Key (UserId) References UserInfo(UserId) NOT NULL , -- UserId ,   RightValue bigint NOT NULL Primary key (UserId, FeedId),   )

Linq插入數(shù)據(jù)的代碼:

RSSFeedRight feedRight = new RSSFeedRight();   feedRight.UserId = userId;    feedRight.FeedId = feedId;    feedRight.RightValue = 0 ;    _Db.RSSFeedRights.InsertOnSubmit(feedRight);    _Db.SubmitChanges();

每次Linq插入數(shù)據(jù)時都提示說FeedId 不能插入空值,郁悶的不行,分明是給了非空值的!

后來仔細檢查,發(fā)現(xiàn)這個RSSFeedRight 實體類中居然還有兩個指向UserInfo 和 RSSFeed 表的字段,后來逐漸感覺到是外鍵設(shè)置問題引起的。立即通過google 搜 "linq foreign key insert",發(fā)現(xiàn)有不少人遇到相同問題,找到其中一篇帖子,其中關(guān)于這個問題是這樣描述的:

The mapping information (Assocation attribute on Table1 & Table2) has the foreign key dependency going in the wrong direction. It's claiming that the primary-key in table1 (the one that is auto-incremented) is a foreign key to the primary key in table2. You want that just the opposite. You can change this in the designer, DBML file or directly in the code (for a quick test) by changing IsForeignKey value for both associations.

也就是說我們不能將主鍵設(shè)置為和外鍵相同,否則就會出問題。找到問題所在,就好辦了,將表結(jié)構(gòu)進行如下修改:

create table RSSFeedRight  (   Id int identity ( 1 , 1 ) NOT NULL Primary Key ,   FeedId int Foreign Key (FeedId) References RSSFeed(FeedId) NOT NULL , -- FeedId ,   UserId int Foreign Key (UserId) References UserInfo(UserId) NOT NULL , -- UserId ,  RightValue bigint NOT NULL ,  )

上述內(nèi)容就是Linq中怎么插入數(shù)據(jù),你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。

新聞名稱:Linq中怎么插入數(shù)據(jù)
當(dāng)前URL:http://chinadenli.net/article20/jiedjo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、虛擬主機、商城網(wǎng)站、App設(shè)計、網(wǎng)站策劃、網(wǎng)站內(nèi)鏈

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護公司