Sam*_*ill 19 entity-framework ef-code-first entity-framework-4.1
我在ASP.NET MVC 3 Web应用程序中使用Entity Framework"Code First"方法.在我的数据库中,我有几个计算列.我需要使用这些列来显示数据(工作正常).
但是当我在这个表中插入行时,我收到以下错误:
无法修改"ChargePointText"列,因为它是计算列或是UNION运算符的结果.
有没有办法在我的课堂上将房产标记为只读?
public class Tariff
{
public int TariffId { get; set; }
public int Seq { get; set; }
public int TariffType { get; set; }
public int TariffValue { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public int ChargePoint { get; set; }
public string ChargePointText { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
Sam*_*ill 33
我找到了解决方案.实体框架提供了一个名为DatabaseGenerated的数据注释.像这样使用它:
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public string ChargePointText { get; set; }
Run Code Online (Sandbox Code Playgroud)
在此处获取更多详细信息:http://msdn.microsoft.com/en-us/library/gg193958.aspx