English 中文(简体)
EF4(实体框架4)的变更表名称
原标题:Change db table name in EF4 (entity framework 4)

是否有任何人知道如何在EF4(实体框架4)中改变一个实体的列表?

后来的编辑: 我认为,在模型浏览器中找到了表格名称定义的地方。 但是,他们的名字只读了,因此不可能用设计师来编辑。 此外,在Xml schema的表格名称上没有提及(从一盘查询)。

最佳回答

如果你真的需要更改表格的名称,你可以:

  1. Open EDMX file with XML Editor.
  2. Locate SSDL section in it.
  3. Locate entity set element for example <EntitySet Name="Customers" EntityType="ExampleModel.Store.Customers" Schema="dbo" />.
  4. Add Table="MyTableName" attribute. <EntitySet Name="Customers" EntityType="ExampleModel.Store.Customers" Schema="dbo" Table="MyTableName" />

http://msdn.microsoft.com/en-us/library/bb399604.aspx” rel=“noreferer”CSDL、SSDL、MSL规格

希望会有所帮助。

问题回答

另一种解决办法是,在您的<代码>DbContext类别中推翻一种方法。

public class MyDbContext : DbContext
{
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Product>().ToTable("DB_PRODUCTS_TBL");
        // otherwise EF assumes the table is called "Products"
    }
}

我认为,你要求的是把一个实体的地图重新编成表格。 你可以点击一个实体,选择表图。 这将向贵实体显示表格的绘制。 你可以改变那里的情况。 然而,当你开始下降时,你只能看到你利用《更新模式》进口的表格。 如果该表没有进口,将不予列入。 然后,你可以把这些财产适当绘制到表格的栏目。

在模型Browser,或设计表面右翼,实体和选定特性。 在财产窗口中,“固定名称”为外地。

这对我来说是行之有效的,但我正在首先设计该表,然后创建数据库。

由于我首先建立了我的数据库,我做了以下工作:

  1. Backed up the *.edmx file.
  2. Changed my database table name.
  3. Did as you suggested by renaming the Entity Set Name in the properties.
  4. I then Updated the model based on my database by right-clicking the entity.
  5. I noticed that the *.edmx file was missing half the lines, so I overlayed the *.edmx file with my backup, opened it in notepad, and did a replace all of my old table name with my new table name.
  6. Rebuilt the MVC Application, tested, and it worked.

Note: Whether all these steps above are needed I don t know, it s just what I tried and it worked for me.

你可以执行一个储存的假体,改变表名称,将表格名称作为变量。 然后将所储存的矿石进口到EF4。

CREATE PROCEDURE ChangeTableName
    @TableName varchar(200)
AS
BEGIN
    SET NOCOUNT ON;
    EXEC sp_rename "User", @TableName
END
GO




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签