开发者

MVC3 naming a column beginning with a number

I am new to MVC3 C#. I need to have a column in the database called 3DSecureStatus for legacy purposes.

When I call the column this and insert in the application I get this error:

[ModelValidationException: One or more validation errors were detected during model generation:

System.Data.Edm.EdmProperty: Name: The specified name is not allowed: '_3DSecureStatus'. ]

In the application I am defining it as public string _3DSecureStatus {开发者_运维问答 get; set; } because it doesn't like 3 being the first character of the column name.

Any suggestions what to do?


Use the Column attribute to specify the database column name

[Column("3DSecureStatus")]
public string ThreeDSecureStatus { get; set; }

Or use fluent mapping like

Property(x => x.ThreeDSecureStatus).HasColumnName("3DSecureStatus");


Rename _3DSecureStatus to something else.

Entity Framework Code First does not allow properties/columns to have underscores or numbers in the beginning of the name.

So you have to change this until this is fixed.


This is actually an Entity Framework error rather then an MVC error. It looks like from a bit of googling that underscores as the start of Code First field names are invalid and don't work. If you can, try putting a letter in front of it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜