在WCF数据服务应用程序中迁移Entity Framework 6和VS2013后无法更新或删除

时间:2013-12-02 15:50:18

标签: c# wcf entity-framework wcf-data-services

迁移到EntityFramework和VS 2013后,我无法更新或删除资源。

Request URL:service.svc/Orders(22354)
Request Method:DELETE
Status Code:500 Internal Server Error
Request Headersview source
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,fr;q=0.6
Host:localhost
Origin:http://localhost
Proxy-Connection:keep-alive
Referer:orders.html
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)         Chrome/31.0.1650.57 Safari/537.36
X-Requested-With:XMLHttpRequest

我有以下错误:

   <?xml version="1.0" encoding="UTF-8"?>
   <m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
       <m:code />
       <m:message xml:lang="fr-FR">An error occurred while processing this request.</m:message>
       <m:innererror>
           <m:message>Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "System.Data.Services.resources" was correctly embedded or linked into assembly "Microsoft.OData.EntityFrameworkProvider" at compile time, or that all the satellite assemblies required are loadable and fully signed.</m:message>
           <m:type>System.Resources.MissingManifestResourceException</m:type>
           <m:stacktrace>at System.Resources.ManifestBasedResourceGroveler.HandleResourceStreamMissing(String fileName)&#xD;
      at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark&amp; stackMark)&#xD;
      at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark&amp; stackMark)&#xD;
      at System.Resources.ResourceManager.InternalGetResourceSet(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents)&#xD;
      at System.Resources.ResourceManager.GetString(String name, CultureInfo culture)&#xD;
      at System.Data.Services.TextRes.GetString(String name, Object[] args)&#xD;
      at System.Data.Services.Providers.ObjectContextServiceProvider.SetConcurrencyValues(Object resource, Nullable`1 checkForEquality, IEnumerable`1 concurrencyValues)&#xD;
      at System.Data.Services.UpdatableWrapper.SetETagValues(Object resourceCookie, ResourceSetWrapper container)&#xD;
      at System.Data.Services.DataService`1.HandleDeleteOperation(RequestDescription description, IDataService dataService)&#xD;
      at System.Data.Services.DataService`1.ProcessIncomingRequest(RequestDescription description, IDataService dataService)&#xD;
      at System.Data.Services.DataService`1.HandleNonBatchRequest(RequestDescription description)&#xD;
      at System.Data.Services.DataService`1.HandleRequest()</m:stacktrace>
       </m:innererror>
   </m:error>

有什么想法吗?

感谢您的帮助。

3 个答案:

答案 0 :(得分:1)

如果有人想尝试这个解决方案......我遇到了同样的问题。如果我将一个分离的实体附加到上下文然后尝试更新/删除它,似乎会出现此错误。

Entity entity; //detached

context.AttachTo("entitySetName", entity);
context.DeleteObject(entity);
context.SaveChanges(); //exception

这对我有用。

//get entity from context instead of attaching the "old" one
var newEntity = ctx.Table.Where(w => w.ID == Entity.ID).FirstOrDefault();

context.DeleteObject(newEntity);
context.SaveChanges(); //works

答案 1 :(得分:0)

在我们的例子中,让客户端集SaveChangesOptions.Batch抛出此异常。将它设置为SaveChangesOptions.BatchWithIndependentOperations没有抛出,但我们不能在我们的场景中使用BatchWithIndependentOperations。希望这可以节省别人浪费的时间。

答案 2 :(得分:0)

对于那些没有使用Microsoft OData客户端的人,我通过强制我的客户端使用MERGE请求更新而不是PUT来解决这个问题。