简体   繁体   English

WCF数据服务-保存嵌套/相关实体

[英]WCF Data Service - Save Nested/Related Entities

We are using the following system setup: 我们正在使用以下系统设置程序:

  • WCF Data Services 5.1.0-RC2 WCF数据服务5.1.0-RC2
  • Entity Framework 4.0 实体框架4.0

Problem: We are trying to create and save nested/related entities on client side using WCF Data Services. 问题:我们正在尝试使用WCF数据服务在客户端上创建和保存嵌套/相关实体。 If we try to save using following code: 如果我们尝试使用以下代码进行保存:

ParentEntity pEntity = context.pEntity;
ChildEntity cEntity = new ChildEntity();
pEntity.childEntities.Add(cEntity);
context.SaveChanges();

then it doesn't work. 那就行不通了 Nothing is saved at the Database and there is no exception thrown. 什么都不会保存在数据库中,也不会抛出异常。 This is normally working fine with only the Entity Model, but not in connection with the WCF Data Service. 通常,这仅对实体模型有效,而对WCF数据服务则无效。

Can you also call the following API before SaveChanges call: 您还可以在SaveChanges调用之前调用以下API:

context.AddRelatedObject("ParentEntitySet", "childEntities", cEntity); context.AddRelatedObject(“ ParentEntitySet”,“ childEntities”,cEntity);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM