Entity Framework does not generates ObservableCollection(实体框架不生成 ObservableCollection)
问题描述
我在我的数据输入程序中使用 EF6.EF 不生成 ObservableCollection 而是生成 HashSet 和 ICollection,所以我必须手动更改它.不幸的是,每次我从数据库更新模型时,每个多对多关系都会回到 ICollection ...
Im using EF6 in my dataentry program. EF does not generates ObservableCollection but HashSet and ICollection instead , so i have to change it manually. Unfortunately every time i Update Model from Database , every Many-Many relation goes back to ICollection ...
推荐答案
将您的 .tt
文件中的 ICollection 和 HashSet 替换为 ObservableCollection.
然后搜索方法public string UsingDirectives
.
在这个方法中应该有一行 includeCollections ?(Environment.NewLine +使用 System.Collections.Generic;"):",
.
仅将 Generic
替换为 ObjectModel
.这将包括正确的命名空间以在您的模型中使用 ObservableCollections.
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.
这篇关于实体框架不生成 ObservableCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:实体框架不生成 ObservableCollection


基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01