在Visual Studio 2012中,我有一個使用實體框架(版本6.1.3)的C#項目。如何防止Visual Studio 2012重命名成員類型(使用實體框架)?
每次我對.edmx文件進行修改並保存時,.tt文件下的.cs類都會重新生成。問題是我在數據庫中有一個名爲「System」的表(不是我的想法),所以每次重新生成類時,Visual Studio都會放置一個「System」。在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 System.Guid CreatedByID { get; set; }
public System.DateTime CreatedOn { get; set; }
}
}
這會導致編譯錯誤,因爲它正在尋找,而不是系統命名空間實體對象的「系統」的GUID和DateTime成員。 因此,每次我對.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; }
}
}
在Visual Studio中是否存在某個選項或者某種方式來配置更改.edmx文件不會添加這些「System」。在Guid和DateTime類型前面?
編輯: 也就是說,一個選項,將停止這一行爲,而不必重命名系統表/類
感謝您使用自動生成的代碼和類
重命名你的'系統'實體,這永遠不是一個好主意。當你爲它命名它也使用它時,VS會爲你區分它的類型。 「消息」是另一個問題。 – TestWell
我知道,但現在我堅持使用它,所以我正在尋找一種解決方案,而不是更改實體名稱。我編輯了這個問題來添加這個規範 –