简体   繁体   中英

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-

在此处输入图片说明

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-

在此处输入图片说明

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.

I don't know about MySQL but this will fix your model in SQL Server:

[Column("number")]
public string number1 { get; set; }

If not you should override the OnModelCreating in your db context.

Test this and tell me to post the other way if this doesn't work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM