Entity Framework does not generates ObservableCollection

走远了吗. 提交于 2019-12-03 07:11:20

Replace ICollection and HashSet with ObservableCollection in your .tt file.
Then search for the method public string UsingDirectives.
In this method there should be a line includeCollections ? (Environment.NewLine + "using System.Collections.Generic;") : "",.
Replace only Generic with ObjectModel. This will include the correct namespace to use ObservableCollections in your models.

  1. Open the Solution Explorer and find .edmx file
  2. Find the .tt file which will be nested under the .edmx file
  3. Double-click on the XXXModel.tt file to open it in the Visual Studio editor
  4. Find and replace the two occurrences of “ICollection” with “ObservableCollection”. These are located approximately at lines 296 and 484.
  5. Find and replace the first occurrence of “HashSet” with “ObservableCollection”. This occurrence is located approximately at line 50. Do not replace the second occurrence of HashSet found later in the code.
  6. Find and replace the only occurrence of “System.Collections.Generic” with “System.Collections.ObjectModel”. This is located approximately at line 424.
  7. Save the XXXModel.tt file. This should cause the code for entities to be regenerated. If the code does not regenerate automatically, then right click on XXXModel.tt and choose “Run Custom Tool”.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!