以下圖來說,正常情況下 edmx 內有 Address 存在,AdventureWorks2019.tt 檔案下應該要產生 Address class 才對
相關錯誤訊息
錯誤 正在執行轉換: System.NullReferenceException: 並未將物件參考設定為物件的執行個體。
於 Microsoft.VisualStudio.TextTemplating548217BD8377E326AEE514EAE722C9BA6586C4151F980CA7BACC70A5732FC55F588FBC8794326CD64388F9B4C50AD7729497DE610EBC8D6F64F48BB130F68063.GeneratedTextTransformation.DynamicTextTransformation.get_GenerationEnvironment()
於 Microsoft.VisualStudio.TextTemplating548217BD8377E326AEE514EAE722C9BA6586C4151F980CA7BACC70A5732FC55F588FBC8794326CD64388F9B4C50AD7729497DE610EBC8D6F64F48BB130F68063.GeneratedTextTransformation.EntityFrameworkTemplateFileManager..ctor(Object textTransformation)
於 Microsoft.VisualStudio.TextTemplating548217BD8377E326AEE514EAE722C9BA6586C4151F980CA7BACC70A5732FC55F588FBC8794326CD64388F9B4C50AD7729497DE610EBC8D6F64F48BB130F68063.GeneratedTextTransformation.EntityFrameworkTemplateFileManager.VsEntityFrameworkTemplateFileManager..ctor(Object textTemplating)
於 Microsoft.VisualStudio.TextTemplating548217BD8377E326AEE514EAE722C9BA6586C4151F980CA7BACC70A5732FC55F588FBC8794326CD64388F9B4C50AD7729497DE610EBC8D6F64F48BB130F68063.GeneratedTextTransformation.EntityFrameworkTemplateFileManager.Create(Object textTransformation)
於 Microsoft.VisualStudio.TextTemplating548217BD8377E326AEE514EAE722C9BA6586C4151F980CA7BACC70A5732FC55F588FBC8794326CD64388F9B4C50AD7729497DE610EBC8D6F64F48BB130F68063.GeneratedTextTransformation.TransformText()
在網路上找到該篇討論 - Create or recreate a Model does not works any more for winform .net framework solutions 確定問題點在哪,雖然有人提出該問題已經修正,詳見該 commit,但在我的VS IDE 環境內還是出現該問題根據討論內容,直接修正 EF6.Utility.CS (C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Templates\Includes\EF6.Utility.CS)
修正後內容
private DynamicTextTransformation(object instance)
{
_instance = instance;
Type type = _instance.GetType();
_write = type.GetMethod("Write", new Type[] { typeof(string) });
_writeLine = type.GetMethod("WriteLine", new Type[] { typeof(string) });
_generationEnvironment = type.GetProperty("GenerationEnvironment"); // 修正該行
_host = type.GetProperty("Host");
_errors = type.GetProperty("Errors");
}
修正內容為// 把
_generationEnvironment = type.GetProperty("GenerationEnvironment", BindingFlags.Instance | BindingFlags.NonPublic);
// 修正為
_generationEnvironment = type.GetProperty("GenerationEnvironment");
重開 VS 後,edmx 就恢復正常啦
- 參考資料
- FB 社團討論
沒有留言:
張貼留言