【发布时间】:2013-07-11 04:55:39
【问题描述】:
我目前正在使用来自 C#(一个 asp.net mvc4 应用程序)的 WCF 数据服务来使用来自 Sharepoint 2010 的信息。
对于常规的 Sharepoint 列表项,在将更改保存到上下文时,新项的 id 会自动填充到原始对象上。含义:
SomeContext context = /* creation of the context*/;
var someEntity = new SomeEntity {...};
context.AddToSomeEntityItems(someEntity);
context.SaveChanges();
var newId = someEntity.Id; //this will have the new id
但是,如果您正在创建的是文档库的项目,则 id 似乎不会在已保存的实体上更新。例如:
SomeContext context = /* creation of the context*/;
var someOtherEntity = new SomeOtherEntity {...};
Stream data = /* some stream*/;
context.AddToSomeOtherEntityItems(someOtherEntity);
context.SetSaveStream(someOtherEntity, data, true, "SomeMIMEType", "SomeSlugPath");
context.SaveChanges();
var newId = someOtherEntity.Id; //this will instead always have 0
我最初认为这是 WCF 数据服务的第一个版本中的一个错误,所以我更新到最新版本,5.4.0。但行为似乎是一样的。
我宁愿避免在重负载期间最终可能失败的奇怪查找,例如使用.OrderByDescending(x => x.Id).First() 来获取最近创建的项目。
当使用 Fiddler 查看实际的网络流量时,我可以看到二进制数据的初始上传实际上确实返回了项目的信息及其 ID。如果我在保存更改之前使用SetLink 配置与该项目的其他关系,它们会正确链接,因此上下文会相应地处理该值。
当项目用于文档库时,有什么方法可以让 WCF 数据服务更新实体上的 ID?
【问题讨论】:
-
哇,我真的是唯一一个使用 WCF 数据服务处理数据流场景的人吗?
-
在这种情况下,什么是有效的 slug 路径?当我尝试这样做时,我不断收到错误,但我没有得到任何有关导致错误的信息stackoverflow.com/questions/35523373/…
标签: c# sharepoint-2010 wcf-data-services odata