问题描述
我已经看过类似的问题,建议我应该使用column属性来更改列的名称,但是我已经做到了,我仍然会收到错误。这是我的Model类: public class Task
{
public int TaskID {get;组; }
public string TaskDescription {get;组; }
public bool IsDone {get;组; }
[Column(Active)]
public bool _destroy {get;组; }
}
问题是实体框架不允许实体属性名称以下划线字符(包括其他字符类)开头。使用反射器,我能够跟踪用于验证属性名称的正则表达式,它是以下内容:
@ \p {的L1} \p {路} \p {LT} \p {罗} \p {Lm的} \p {NL}] [{\p的L1} \p {路} \p {LT} \p {罗} \p {Lm的} \p {NL} \p {锰} \p {了Mc} \p {钕} \p {PC} \ p {Cf}] {0,}
这意味着实体属性名称只能以字符开头取自以下Unicode字符类:
L1,Lu,Lt,Lo,Lm,Nl
属性名称中的剩余字符可能包括以下类别:
Mn,Mc,Nd,Pc,Cf
下划线字符(U + 005F)在Pc类中。您可以通过重命名_destroy属性来删除错误,如destroy。您可以在这里找到一个字符类参考。
I have looked at similar questions that suggest I should use the column attribute to change the name of the column, but I have done this and I still get the error. Here is my Model class:
public class Task
{
public int TaskID { get; set; }
public string TaskDescription { get; set; }
public bool IsDone { get; set; }
[Column("Active")]
public bool _destroy { get; set; }
}
The problem is that Entity Framework does not allow entity property names to begin with underscore characters (among other character classes). Using Reflector, I was able to track down the regex used to validate property names, and it is the following:
@"[\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Lm}\p{Nl}][\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Lm}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\p{Cf}]{0,}"
This means that entity property names can begin only with characters taken from the following Unicode character classes:
Ll, Lu, Lt, Lo, Lm, Nl
The remaining characters in a property name may include those classes, as well as the following:
Mn, Mc, Nd, Pc, Cf
The underscore character (U+005F) is in the Pc class. You can remove the error by renaming the _destroy property as, say destroy. You can find a character class reference here.
这篇关于如何修复错误名称:不允许指定的名称:_destroy?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!