EF代码第一表命名问题 [英] EF Code First table naming issues

查看:108
本文介绍了EF代码第一表命名问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用EF代码建立的项目。它还使用表单身份验证。直到最近,会员数据库和应用程序数据库都是单独开发的,但为了简单起见,我想将它们组合成一个数据库。



我的代码第一个模型中的一个类称为应用程序,因此EF生成的表称为应用程序,它与同名的成员资格表冲突。这是我当前上下文的一个例子:

  public partial class ExampleContext:DbContext 
{
public DbSet< ;应用程序>应用{get;组; }
public DbSet< Status> StatusTypes {get;组; } //注意属性的名称与类的名称
}

我认为表名称是基于上下文中属性的名称,因为它为所有的状态生成了一个名为 StatusTypes 的表。 code>对象。但是,如果将应用程序属性重命名为 MyApplications ,它仍然生成一个名为应用。很明显,这不仅仅是财产的名称,而且我也缺少一些东西。



我的问题:我如何让EF以不同的方式来命名这个表?

解决方案

我只是重命名了这个类,它的工作。现在最简单的解决方案。


I have a project built using EF code first. It also uses forms authentication. Until recently the membership database and the application database were being developed separately, but I want to combine them into one database for simplicity.

One of the classes in my code first model is called "Application" so the EF-generated table is called "Applications" which conflicts with a membership table of the same name. This is an example of my current context:

public partial class ExampleContext : DbContext
{
    public DbSet<Application> Applications { get; set; }
    public DbSet<Status> StatusTypes { get; set; } // notice the name of the property vs the name of the class
}

I thought the table names were based on the names of the properties in the context, because it was generating a table named StatusTypes for all of the Status objects. But if I rename the Applications property to something like MyApplications it is still generating a table named Applications. So clearly it's not just the name of the property and I'm missing something.

My question: how do I get EF to name this table differently?

解决方案

I just renamed the class and it worked. Easiest solution for now.

这篇关于EF代码第一表命名问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆