Entity framework 如何使用RIA服务和实体框架将实体集合保存到数据库?
我可以在视图模型中添加到集合,在方法上添加到集合,在提交更改:Entity framework 如何使用RIA服务和实体框架将实体集合保存到数据库?,entity-framework,wcf-ria-services,silverlight-5.0,Entity Framework,Wcf Ria Services,Silverlight 5.0,我可以在视图模型中添加到集合,在方法上添加到集合,在提交更改: public void AddEntityDetail() { this.IsBusy = true; this.entityContext.SubmitChanges(OnSubmitChangesCompleted, null); } public void AddEntityCollection(EntityDetail entityDetail)
public void AddEntityDetail()
{
this.IsBusy = true;
this.entityContext.SubmitChanges(OnSubmitChangesCompleted, null);
}
public void AddEntityCollection(EntityDetail entityDetail)
{
if (!this.entityDetailContext.EntityDetails.Contains(entityDetail))
this.entityDetailContext.EntityDetails.Add(entityDetail);
}
我目前不知道如何通过服务传递此信息并将其添加到数据库中。
此外,此实体未绑定到xaml。WCF RIA服务的整个要点在于它为您隐藏了数据传输 您只需对数据集执行CRUD操作并调用
SubmitChanges()
。SubmitChanges创建一个变更集(字面上是所做的一组变更)并将其传输到服务器
服务器端通过依次调用方法,为每种对象类型调用各种RIA服务器CRUD方法,直到处理完所有更改。方法由参数和返回类型匹配
套用我先前的回答:
On the receiving side it goes through all the changes and says:
Q. "Is this an object deletion?"
A. Yes...
Q. "What object type is it?"
A. BlahBlah
Q. "Do we have a method called Delete that takes a BlahBlah parameter?"
A. Yes...
It then calls that method with the object from the changeset
Rinse and repeat for all other changes.
您不需要将任何内容传递给服务。SubmitChanges方法可以做到这一点。绑定本身或xaml中的绑定也不会影响任何内容。