Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在SubmitChanges()上插入时,将服务器所做更改的已提交实体返回到客户端_C#_Silverlight_Wcf Ria Services - Fatal编程技术网

C# 在SubmitChanges()上插入时,将服务器所做更改的已提交实体返回到客户端

C# 在SubmitChanges()上插入时,将服务器所做更改的已提交实体返回到客户端,c#,silverlight,wcf-ria-services,C#,Silverlight,Wcf Ria Services,我正在研究SOA体系结构。所以我无法访问数据库。我使用服务器上的DTO作为实体。我在客户机上填写一个实体并将其提交给服务器,这就是为该实体生成主键的时候 我使用(客户端) _customerDomainContext.SubmitChanges(SubmitChangesCalback,null) 在回调中,当我尝试访问新添加的enity时,我只能看到我填写的属性 我可以访问域服务(服务器端)上提交的实体,如下所示 [Insert] public void InsertCustom

我正在研究SOA体系结构。所以我无法访问数据库。我使用服务器上的DTO作为实体。我在客户机上填写一个实体并将其提交给服务器,这就是为该实体生成主键的时候

我使用(客户端)

_customerDomainContext.SubmitChanges(SubmitChangesCalback,null)

在回调中,当我尝试访问新添加的enity时,我只能看到我填写的属性

我可以访问域服务(服务器端)上提交的实体,如下所示

   [Insert]
    public void InsertCustomerDTO(CustomerDTO customer)
    {
      CustomerDTO customerFromDB = CreateCustomerDTOCore(customer);
    }
是否有办法将新生成的实体发送到客户端,以便在提交更改时访问该实体新生成的密钥


非常感谢您的建议。

只需使用回调的参数:

context.SubmitChanges(x =>
            {
                //Contains your entities fulfilled by the server
                x.ChangeSet
            }, null);
它包含保存后服务器返回的实体,因此在密钥字段中可以找到实际的密钥值。
为了运行上述过程,您可能不需要“编辑”实体

[Insert]
public void InsertJeopardyModel(CustomerDTO jeopardy)
{
    CustomerDTO customerFromDB = CreateCustomerDTOCore(customer);
    jeopardy.Id = customerFromDB.Id;
    jeopardy.MyProperty = customerFromDB.MyDBEquivalentProperty;
}
正如您在编辑的示例中所看到的,我实际上正在编辑CustomerTo对象,就像Enitity Framework或LINQ2SQL一样

然后,编辑的实体将被序列化到客户端,该客户端将在
变更集
属性中公开该实体。

我尝试了此选项,但变更集仅返回从客户端发送的值。如果我使用EntityFramework,它也会降低Id,但我使用POCO对象。这可能是因为您没有更改作为参数传递的实体。我用服务器端方法改进了我的答案