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

Linq插入數(shù)據(jù)問題怎么解決

這篇文章主要講解了“Linq插入數(shù)據(jù)問題怎么解決”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“Linq插入數(shù)據(jù)問題怎么解決”吧!

創(chuàng)新互聯(lián)專業(yè)網(wǎng)站建設(shè)、成都網(wǎng)站制作,集網(wǎng)站策劃、網(wǎng)站設(shè)計(jì)、網(wǎng)站制作于一體,網(wǎng)站seo、網(wǎng)站優(yōu)化、網(wǎng)站營銷、軟文發(fā)布平臺等專業(yè)人才根據(jù)搜索規(guī)律編程設(shè)計(jì),讓網(wǎng)站在運(yùn)行后,在搜索中有好的表現(xiàn),專業(yè)設(shè)計(jì)制作為您帶來效益的網(wǎng)站!讓網(wǎng)站建設(shè)為您創(chuàng)造效益。

今天用Linq插入數(shù)據(jù),總是插入錯誤,說某個主鍵字段不能為空,我檢查了半天感覺主鍵字段沒有賦空值啊,實(shí)在是郁悶。

要插入數(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),  )

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

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

每次插入時都提示說FeedId 不能插入空值,郁悶的不行,分明是給了非空值的!

后來仔細(xì)檢查,發(fā)現(xiàn)這個RSSFeedRight 實(shí)體類中居然還有兩個指向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)進(jìn)行如下修改:

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

感謝各位的閱讀,以上就是“Linq插入數(shù)據(jù)問題怎么解決”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對Linq插入數(shù)據(jù)問題怎么解決這一問題有了更深刻的體會,具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點(diǎn)的文章,歡迎關(guān)注!

網(wǎng)頁標(biāo)題:Linq插入數(shù)據(jù)問題怎么解決
分享路徑:http://chinadenli.net/article18/gohddp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護(hù)做網(wǎng)站、響應(yīng)式網(wǎng)站移動網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)公司網(wǎng)站改版

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎ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è)公司