EF代码第一表命名问题 [英] EF Code First table naming issues
问题描述
我的代码第一个模型中的一个类称为应用程序,因此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屋!