“集团”是保留关键字,不能用作别名,除非转义
我正在使用带有存储库模式的实体框架 4.1(数据库已存在)。 我的问题是存在一个名为 GROUP 的表(已保留)。这是我无法更改的生产数据库。
因此,使用上述所有这些技术,我收到以下错误:
“Group”是保留关键字,不能用作别名,除非对其进行转义。
是否可以告诉实体框架使用以下内容作为表名: [组]
编辑 具有数据库上下文的类如下所示(精简)
public class AMTDatabase : DbContext
{
private IDbSet<GROUP> _Groups;
public IDbSet<GROUP> Group
{
get { return _Groups ?? (_Groups = DbSet<GROUP>()); }
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<GROUP>().ToTable("GROUP");
}
//etc
}
提前致谢
I'm using Entity Framework 4.1 with repository pattern (Database is already existing).
My problem is the existence of a table called GROUP (which is reserved). This is a production database which i cannot change.
So, using all this techniques above i'm getting the following error:
'Group' is a reserved keyword and cannot be used as an alias, unless it is escaped.
Is it possible to tell Entity Framework to use the following as the table name:
[GROUP]
EDIT
The class with the db context looks like the following (stripped down)
public class AMTDatabase : DbContext
{
private IDbSet<GROUP> _Groups;
public IDbSet<GROUP> Group
{
get { return _Groups ?? (_Groups = DbSet<GROUP>()); }
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<GROUP>().ToTable("GROUP");
}
//etc
}
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,这看起来很奇怪,但请注意上面的属性名称:名称是 Group,它应该读作 Groups!这就是我收到此错误的原因。更正后的代码如下:
现在就像魅力一样!
Well it seems very weird, but notice the property name above: the name is Group and it should read Groups! This is the reason i'm getting this error. The corrected code is the following:
Works like a charm now!
尝试为您的类使用其他命名,并告诉他使用数据库中的 Group 表,如下所示:
或者直接使用实体类上的属性:
Try to use another naming for you class and tell him to use the Group table in your database like so:
Or with the attributes directly on your entity class: