久久久久久久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 的方法調用)
主站蜘蛛池模板: 老司机午夜性大片 | 一区欧美| 精品一区电影 | 精品国模一区二区三区欧美 | 国产精品一区二区三级 | 日韩欧美在 | 国产1区2区在线观看 | 精品欧美一区二区三区久久久 | 国产精久久久久久 | 成人免费看片又大又黄 | 不卡av在线| 911网站大全在线观看 | 久草网址| 91av免费看 | 免费在线色 | av手机免费在线观看 | 欧美精品一区三区 | 狠狠av | 一级大片网站 | 中文字幕乱码一区二区三区 | 成人av鲁丝片一区二区小说 | 天天色天天射天天干 | 亚洲一区国产精品 | a毛片| 国产精品久久久久av | 国产精品成人在线播放 | 亚洲精品国产a久久久久久 午夜影院网站 | 欧美在线一区二区三区四区 | 成人在线免费观看 | 亚洲欧美日韩精品久久亚洲区 | 亚洲欧美日韩中文在线 | 一区二区三区日韩 | 91久久精品| 国产精品免费视频一区 | 精品国产91亚洲一区二区三区www | 国产成人精品亚洲日本在线观看 | 天天操夜夜操 | 美女亚洲一区 | 在线播放国产一区二区三区 | 青青久久 | 久久国产综合 |