[英]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.