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.