asp.net ChangeAction - 简单的教程问题

时间:2010-10-15 17:23:52

标签: asp.net-mvc

partial void OnValidate(ChangeAction action) {
if (!IsValid)
throw new ApplicationException("Rule violations prevent saving");
}

我正在学习本教程:

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

请原谅初学者的问题,如果您需要任何其他细节,请告诉我。我几乎可以肯定,我错过了一些基本的东西。有人可以帮忙吗?让我完成必要的步骤?

1 个答案:

答案 0 :(得分:4)

您使用其非限定名称引用ChangeAction,因此您必须从模块中显示其命名空间:

using System.Data.Linq;

如果上面给出了错误,您可能还应该将System.Data.Linq程序集添加到项目的引用中。