久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

LINQ 中的實體附件問題

Entity attachment issues in LINQ(LINQ 中的實體附件問題)
本文介紹了LINQ 中的實體附件問題的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我從表單 POST 接收到 LINQ 實體后,嘗試將其附加到數據上下文.但是,我得到的只是以下異常:

I am trying to attach a LINQ entity to the data context after I receive it from a form POST. However, all I get is the following exception:

An entity can only be attached as modified without original state if it declares a version member or does not have an update check policy.

我也嘗試附加原始行,如下所示:

I have also tried attaching the original row, like so:

dataContext.People.Attach(person, originalPerson);

在這種情況下,我得到以下異常:

In this case, I get the following exception:

Object reference not set to an instance of an object.

這是我的控制器中的代碼:

Here's the code in my controller:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, Person person) {
    var prevPerson = dataContext.People.Single(p => p.ID == id);
    dataContext.People.Attach(person, prevPerson);
    dataContext.SubmitChanges();
    return Redirect("~/People/Index");
}

對我在這里做錯了什么有任何想法嗎?如果需要,我可以發布實體代碼.

Any ideas on what I'm doing wrong here? I can post the entity code if needed.

推薦答案

在 LinqToSQL 設計器中,將所有更新檢查設置為從不,當你附加時,像這樣調用它:

In the LinqToSQL designer set all of the Update Checks to Never and when you attach call it like so:

 context.entity.Attach(entity, true);

或者,您也可以從數據庫中獲取實體并使用來自 POSTed 實體的數據對其進行更改,然后將其作為更改提交.

Alternatively, you could also grab the entity from the db and change it using the data from the POSTed entity, then submit that as a change.

這篇關于LINQ 中的實體附件問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Why shouldn#39;t I always use nullable types in C#(為什么我不應該總是在 C# 中使用可空類型)
C# HasValue vs !=null(C# HasValue vs !=null)
C# ADO.NET: nulls and DbNull -- is there more efficient syntax?(C# ADO.NET:空值和 DbNull —— 有沒有更高效的語法?)
How to set null value to int in c#?(如何在c#中將空值設置為int?)
How to handle nulls in LINQ when using Min or Max?(使用 Min 或 Max 時如何處理 LINQ 中的空值?)
Method call if not null in C#(在 C# 中如果不為 null 的方法調用)
主站蜘蛛池模板: 成人黄色在线 | 久国产精品 | 日日操操操 | 一区二区精品视频 | 四虎影院免费在线播放 | 久久国产区| 老司机午夜性大片 | 国产二区在线播放 | 国产在线观 | 国产精品久久久久久52avav | 欧美综合一区二区三区 | 狠狠亚洲| 中文字幕日韩欧美一区二区三区 | 久久精品国产免费高清 | 久久久91 | 亚洲在线一区二区三区 | 国产精品一区一区三区 | 91精品国产综合久久久久久丝袜 | 九九热在线免费视频 | 成人在线视频网站 | 久久亚洲欧美日韩精品专区 | 中文字幕在线观看一区 | 蜜臀久久 | 亚洲国产成人精品在线 | 国产精品久久久久久久久久久久午夜片 | av av在线| 色久电影 | 视频一区中文字幕 | 午夜黄色影院 | 亚洲高清视频一区二区 | 91精品国产91久久综合桃花 | 欧美精品在线免费观看 | 性在线 | 99久久久99久久国产片鸭王 | 久久久精品网 | 国产一区二区三区四区三区四 | 日韩精品一区中文字幕 | 成人a视频片观看免费 | 欧美精品在线一区二区三区 | 91精品国产综合久久久密闭 | 日韩欧美中文字幕在线观看 |