简体   繁体   English

如何防止Visual Studio 2012重命名成员类型(使用Entity Framework)?

[英]How to prevent Visual Studio 2012 from renaming member types (using Entity Framework)?

In Visual Studio 2012, I have a C# project using the Entity Framework (version 6.1.3). 在Visual Studio 2012中,我有一个使用Entity Framework(版本6.1.3)的C#项目。

Everytime I make modifications to the .edmx file and save them, the .cs classes under the .tt file are re-generated. 每次我对.edmx文件进行修改并将其保存时,都会重新生成.tt文件下的.cs类。 The problem is that I have a table named "System" in the database (not my idea), so everytime the classes are re-generated, Visual Studio places a "System." 问题是我在数据库中有一个名为“ System”的表(不是我的主意),因此每次重新生成类时,Visual Studio都会放置一个“ System”。 in front of Guid and DateTime members 在Guid和DateTime成员面前

Sample code: 样例代码:

namespace ProjectName.Data
{
    using global::System;
    using global::System.Collections.Generic;

    public partial class Area
    {
        public int AreaID { get; set; }
        public int SystemID { get; set; }
        public string Code { get; set; }
        public string Name { get; set; }
        public bool Enabled { get; set; }
        public System.Guid CreatedByID { get; set; }
        public System.DateTime CreatedOn { get; set; }
    }
}

This causes compilation errors because it is looking for the Guid and DateTime members of the Entity object "System", instead of the System namespace. 这会导致编译错误,因为它正在寻找实体对象“ System”的Guid和DateTime成员,而不是System名称空间。 So everytime I make a change to the .edmx file, I have to do a Search and Replace in all files to change "System.DateTime" to "DateTime" and "System.Guid" to "Guid", to give the following: 因此,每次更改.edmx文件时,都必须在所有文件中进行搜索和替换,以将“ System.DateTime”更改为“ DateTime”,将“ System.Guid”更改为“ Guid”,以提供以下信息:

namespace ProjectName.Data
{
    using global::System;
    using global::System.Collections.Generic;

    public partial class Area
    {
        public int AreaID { get; set; }
        public int SystemID { get; set; }
        public string Code { get; set; }
        public string Name { get; set; }
        public bool Enabled { get; set; }
        public Guid CreatedByID { get; set; }
        public DateTime CreatedOn { get; set; }
    }
}

Is there an option somewhere in Visual Studio or some way to configure that changing the .edmx file doesn't add those "System." 在Visual Studio的某处是否有一个选项,或以某种方式配置更改.edmx文件不会添加那些“系统”。 in front of Guid and DateTime types? 在Guid和DateTime类型前面?

EDIT : That is, an option that would stop this behavior without having to rename the System table/class 编辑 :也就是说,可以在不重命名系统表/类的情况下停止此行为的选项

Thank you 谢谢

这就是自动生成的代码和与名称空间名称匹配的类的一个非常普遍的问题(每次在设计器中进行更改时,Windows Designer都会重新添加完全限定名称),只需重命名该类并节省大量时间即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Visual Studio 2012或更高版本中使用Npgsql和Entity Framework的MVC4 - MVC4 using Npgsql and Entity Framework in Visual Studio 2012 or higher 使用Studio和实体框架进行Visual Studio 2012测试 - Visual Studio 2012 testing with csla and entity framework 如何在Visual Studio 2012 C#中使用数据/值成员从组合框执行搜索操作 - How to preform search operation from combobox using data/value member in Visual Studio 2012 C# 使用C#,WPF,实体框架和Visual Studio 2012不会在数据库中更新数据 - Data is not updated in database, using C#,WPF, Entity framework and Visual studio 2012 从Visual Studio 2012移至vs 2010后的实体框架错误 - entity framework error after moving from visual studio 2012 to vs 2010 具有Visual Studio 2010和Entity Framework兼容性的MS SQL Server 2012 - MS SQL Server 2012 with Visual Studio 2010 and Entity Framework compatibility 缺少实体框架连接字符串后的Visual Studio 2012 Stackoverflow - Visual Studio 2012 stackoverflow after entity framework connectionstring missing 如何为Visual Studio 2012 MVC实体框架项目添加Oracle服务器? - How to add an Oracle Server for a Visual Studio 2012 MVC Entity Framework Project? 如何防止Visual Studio重命名我的ID属性? - How do i prevent visual studio from renaming my id attributes? 如何使用Visual Studio 2012从源代码管理中分离项目? - How to Detach a Project from Source Control using Visual Studio 2012?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM