我是否需要添加一个新的实体后打电话到我的域名服务的context.SaveChanges? [英] Do I need to call my domain service's context.SaveChanges after adding a new entity?

查看:134
本文介绍了我是否需要添加一个新的实体后打电话到我的域名服务的context.SaveChanges?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立基于RIA服务的应用程序。

I am building an application based on Ria Services.

当中是被在Visual Studio向导生成的默认方法,我可以看到,应该插入的那些和坚持新的数据。

Amongst the default methods that were built by the Visual Studio Wizard, I can see the ones that should insert and persist new data.

例如:

    public void InsertCustomer(Customer customer)
    {
        if ((customer.EntityState != EntityState.Detached))
        {
            this.ObjectContext.ObjectStateManager.ChangeObjectState(customer, EntityState.Added);
        }
        else
        {
            this.ObjectContext.Customers.AddObject(customer);
        }
    }



不过,我没有看到任何this.ObjectContext .SaveChanges(),我应该读以便插入实体在数据存储调用。 ......我需要以持续的信息来修改这些功能呢?

However, I don't see any this.ObjectContext.SaveChanges(), which I read should be invoked in order to insert the entity in the data store. ...do I need to modify these functions in order to persist the information?

谢谢,
干杯,
赞布罗塔。

Thanks in advance, Cheers, Gianluca.

推荐答案

当你调用客户端上的SubmitChanges,它调用到DomainService.Submit在服务器上。默认的实现依次调用到的若干受保护的虚拟方法,包括AuthorizeChangeSet,ValidateChangeSet,ExecuteChangeSet和PersistChangeSet。您CUD操作将从ExecuteChangeSet和ObjectContext.SaveChanges()将从PersistChangeSet调用被调用。

When you call SubmitChanges on the client, it calls into DomainService.Submit on the server. The default implementation then sequentially calls into a number of protected virtual methods including AuthorizeChangeSet, ValidateChangeSet, ExecuteChangeSet, and PersistChangeSet. Your CUD operation will be invoked from ExecuteChangeSet and ObjectContext.SaveChanges() will be invoked from PersistChangeSet.

您不需要修改默认的方法,坚持信息作为默认情况下将照顾。然而,设计为您提供了覆盖管道提交的大块,如果你发现更复杂的情况是必要的选择。

You don't need to modify the default methods to persist information as that will be taken care of by default. However, the design gives you the option of overriding chunks of the submit pipeline if you find more complex scenarios necessitate it.

这篇关于我是否需要添加一个新的实体后打电话到我的域名服务的context.SaveChanges?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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