我正在为我自己的应用程序使用 MVVM 调整 Windows Phone 数据库示例。在这里,它建议使用允许使用(使用方法)EntitySet
分配的 getter/setter 组合来包装模型对象上的属性,例如IEnumerable
Assign
// Example method from a model class 'SomeModelObject'
[Association(Storage = "_todos", OtherKey = "_categoryId", ThisKey = "Id")]
public EntitySet<ToDoItem> ToDos
{
get { return this._todos; }
set { this._todos.Assign(value); }
}
但是,当我尝试实例化一个具有EntitySet
属性的对象时,它不会允许它,例如
SomeModelObject myModelObject = new SomeModelObject() {
Property1 = "foo",
Property2 = true,
// Following raises an error, even though setter should allow assignment
// from an IEnumerable (because of the use of 'Assign' in the setter)
ToDos = new List<ToDoItem>() {
new ToDoItem(),
},
};
错误如下,
Error 1 Cannot implicitly convert type
'System.Collections.Generic.List<SomeApp.ToDoItem>' to
'System.Data.Linq.EntitySet<SomeApp.ToDoItem>'
如何实例化从 a 引用的对象EntitySet
?