实体框架不生成ObservableCollection [英] Entity Framework does not generates ObservableCollection

查看:121
本文介绍了实体框架不生成ObservableCollection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的数据库程序中使用EF6。 EF不会生成ObservableCollection,而是生成HashSet和ICollection,所以我必须手动更改它。不幸的是,每次我从数据库更新模型,每一个很多关系可以追溯到ICollection ...

解决方案

替换ICollection和HashSet在 .tt 文件中的ObservableCollection。

然后搜索方法 public string UsingDirectives
在这种方法中应该有一行 includeCollections? (Environment.NewLine +using System.Collections.Generic;):,。仅将 Generic ObjectModel 替换。这将包括在模型中使用ObservableCollections的正确命名空间。


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 ...

解决方案

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆