如何使用RIA服务和实体框架将实体集合保存到数据库?

时间:2012-03-02 16:43:08

标签: entity-framework wcf-ria-services silverlight-5.0

我可以在视图模型中添加到集合,添加到集合的方法以及提交更改:

    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。

1 个答案:

答案 0 :(得分:0)

WCF RIA Services的重点在于它为您隐藏数据传输。

您只需对数据集执行CRUD操作并调用SubmitChanges()。 SubmitChanges创建一个变更集(字面意思是一组更改)并将它们传输到服务器。

服务器端通过按顺序调用方法为每种对象类型调用各种RIA Servers 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.
相关问题