2010-10-15 48 views
0
partial void OnValidate(ChangeAction action) { 
if (!IsValid) 
throw new ApplicationException("Rule violations prevent saving"); 
} 

我下面這個教程:asp.net ChangeAction - 簡單教程的問題

http://aspnetmvcbook.s3.amazonaws.com/aspnetmvc-nerdinner_v1.pdf

,我不能夠編譯上面的代碼。它是在我的NerdDinner.Models.Dinner

我把它放在錯誤的位置?

這裏的類:

public partial class Dinner { 
public bool IsValid { 
get { return (GetRuleViolations().Count() == 0); } 
} 
public IEnumerable<RuleViolation> GetRuleViolations() { 
yield break; 
} 
partial void OnValidate(ChangeAction action) { 
if (!IsValid) 
throw new ApplicationException("Rule violations prevent saving"); 
} 
} 

這裏的錯誤即時得到

Error 1 The type or namespace name 'ChangeAction' could not be found (are you missing a using directive or an assembly reference?) 

請原諒初學者的問題,請讓我知道如果你需要任何其他細節。即時通訊幾乎可以肯定,我在這裏失去了一些基本的東西任何人都可以請幫忙嗎?通過必要的步驟來運行我?

+0

我們需要看到更多的代碼,哪個類包含這個方法? – CodingGorilla 2010-10-15 17:27:03

+0

@gorilla:更新謝謝你的幫助 – 2010-10-15 17:28:33

+0

你有沒有創建.dbml文件,你確定你拼寫的一切都一樣嗎? :) – CodingGorilla 2010-10-15 18:08:10

回答

4

你被它的不合格的名稱引用ChangeAction,所以你必須做出自己的命名空間,從你的模塊可見:

using System.Data.Linq; 

如果上面給出了一個錯誤,你可能也應該在System.Data.Linq組件添加到您的項目的參考。

+0

非常感謝你! – 2010-10-15 20:20:52

+0

對我來說我需要將System.Data.Linq程序集添加到項目引用 – Rohit 2013-08-05 16:31:58