[英]Could not use property name as that of class for dbset entity framework
I have a table number as below in mysql server, for heads up I am using MVC4 with EF and MYSql as database- 我在mysql服务器中有一个下表,对于单向来说,我将MVC4与EF和MYSql一起用作数据库-
I used database first approach to add entities to my project and since my table contains the number as property which is also the name of table so EF modal generator added that property as number1 as shown below- 我使用数据库优先方法向项目中添加实体,并且由于我的表包含作为属性的数字,这也是表的名称,因此EF模式生成器将该属性添加为number1,如下所示-
When I try to pull data from database using EF query it throws the error saying- Unknown column 'Extent3.number1' in 'field list' Basically I want to know how can we use same field name inside class as that of class name for modal class generated. 当我尝试使用EF查询从数据库中提取数据时,它抛出错误消息-“字段列表”中的未知列“ Extent3.number1”基本上我想知道我们如何在类内部使用与模态类名称相同的字段名称类生成。
I don't know about MySQL but this will fix your model in SQL Server: 我不了解MySQL,但这将在SQL Server中修复您的模型:
[Column("number")]
public string number1 { get; set; }
If not you should override the OnModelCreating
in your db context. 如果不是,则应在数据库上下文中重写
OnModelCreating
。
Test this and tell me to post the other way if this doesn't work. 测试一下,如果无法正常工作,请告诉我以其他方式发布。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.