【发布时间】:2012-11-14 11:54:20
【问题描述】:
我创建了一个类,它对 MySql 数据库中的现有表进行建模。下面是类:
public class class1
{
[Key]
public int id { get; set; }
public int LastName { get; set; }
public int FirstName { get; set; }
}
我还创建了一个此类。
public class Dbo : DbContext
{
public DbSet<class1> Classs { get; set; }
}
我已经创建了我的控制器。现在,当我运行应用程序时,我收到此错误:
MySql.Data.MySqlClient.MySqlException was unhandled by user code
Message=You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
`LastName` int NOT NULL,
`Fi' at line 2
Source=MySql.Data
ErrorCode=-2147467259
Number=1064
MySql 表有这样的结构:
`id` int(11) NOT NULL,
`LastName` int(11) NOT NULL,
`FirstName` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT
【问题讨论】:
-
代码优先?对我来说,这看起来不像“代码优先”。这些表已经存在,对吧?
-
@spender 那是代码首先与现有数据库。检查codeproject.com/Articles/327945/…。那里的表已经存在。
标签: c# mysql asp.net-mvc visual-studio-2010