问题描述
所以我很远了使用实体框架设计者作出EDMX用作在MVVM项目模型的兔子洞。
我刚刚碰到过,我敢肯定,在的ICollection℃的问题;>
生成的代码(参见下面的示例)确实需要是的ObservableCollection<>
在一个视图绑定收集到的DataGrid
是成功的。
我的认为的我得到关于修改EF代码生成,使的可能性,一些点击 ObservableCollections
,而不是 ICollections
。 ?任何一个曾经试图成功地
我想另一个选择是有一个包含选定的客户对象还包含一个本地的ObservableCollection<虚拟机;排序> ;
选择客户对象时被创建....我只是担心的背景下保存,并保持数据同步
。一个关联到孩子的集合典型的代码生成目标对象:
公共部分类客户
{
酒店的公共客户()
{
this.Orders =新的HashSet<排序>();
}
公众诠释标识{搞定;组; }
公众的System.DateTime日期{搞定;组; }
公共虚拟的ICollection<排序>订单{搞定;组; }
}
的 DbSet
是通过正常暴露类的的DbContext
有一个本地
属性,该属性是一个的ObservableCollection< T>
。请参见了解更多信息。
So I'm pretty far down the rabbit hole of using the Entity Framework designer to make an EDMX that serves as the model in an MVVM project.I've just come across an issue where I'm pretty sure that the ICollection<>
that was code generated (see below for example) really needs to be an ObservableCollection<>
for binding that collection to a DataGrid
in a view to be successful.I think I'm getting some hits on the possibility of modifying the EF code generation to make ObservableCollections
rather than ICollections
. Any one ever tried that successfully?
I suppose another option would be have the VM that contains the selected Customer object also contain a local ObservableCollection<Order>
that gets created when the Customer object is selected....I just worry about the context saves and keeping the data in sync.
typical code gen object with an association to a collection of child objects :
public partial class Customer
{
public Customer()
{
this.Orders = new HashSet<Order>();
}
public int Id { get; set; }
public System.DateTime Date { get; set; }
public virtual ICollection<Order> Orders { get; set; }
}
The DbSet
class that is normally exposed via your DbContext
has a Local
property which is an ObservableCollection<T>
. See the official documentation for more information
这篇关于我怎样才能改变一个实体框架ICollection的是一个ObservableCollection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!