实体框架代码第一计算属性 [英] Entity Framework Code First Computed Properties
问题描述
但是,当我在这个表中插入行时,我收到以下错误: / p>
列ChargePointText不能修改
,因为它是
计算列,或者是
UNION运算符
有没有办法在我的课程中将属性标记为只读方式?
public class Tariff
{
public int TariffId {get;组; }
public int Seq {get;组; }
public int TariffType {get;组; }
public int TariffValue {get;组; }
public string标题{get;组; }
public string描述{get;组; }
public int ChargePoint {get;组; }
public string ChargePointText {get;组; }
}
解。实体框架提供了一个名为DatabaseGenerated的数据注释。使用它像这样:
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public string ChargePointText {get;组;
获取更多详细信息: http://msdn.microsoft.com/en-us/library/gg193958.aspx
I'm using Entity Framework "Code First" approach in a ASP.NET MVC 3 web application. In my database I have several computed columns. I need to use these columns to display data (which works fine).
However when I come to insert rows into this table, I'm getting the following error:
The column "ChargePointText" cannot be modified because it is either a computed column or is the result of a UNION operator.
Is there a way to mark the property as readonly in my class?
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; }
}
I've found the solution. Entity Framework provides a data annotation called DatabaseGenerated. Use it like this:
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
public string ChargePointText { get; set; }
Get more details here: http://msdn.microsoft.com/en-us/library/gg193958.aspx
这篇关于实体框架代码第一计算属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!