我已经在这个问题上工作了一段时间而且无法解决它。任何帮助将不胜感激......
使用Azure表存储(不是开发存储)我只是想从表中删除一行:
Public Sub DeleteByItemId(pairItemId As String)
Dim item = (From c In _ServiceContext.UserTable Where c.Id = pairItemId Select c).Single()
_ServiceContext.DeleteObject(item)
_ServiceContext.SaveChanges()
End Sub
这会导致错误:“上下文当前没有跟踪实体。”
这种方法:
Public Sub DeleteByItemId(itemId As String)
Dim item = New <object type>
item.PartitionKey = "sandbox"
item.RowKey = itemId
_ServiceContext.AttachTo(<table name>, item, "*")
_ServiceContext.DeleteObject(item)
_ServiceContext.SaveChanges()
End Sub
错误:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code>InvalidInput</code>
<message xml:lang="en-US">One of the request inputs is not valid.
RequestId:e37b0824-3336-4089-b6ac-2824438618f6
Time:2012-08-07T01:37:28.2741813Z</message>
</error>
如何创建服务上下文:
Public Sub New()
Dim storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString")
_ServiceContext = New OroosoUserPairedAccountDataServiceContext(storageAccount.TableEndpoint.ToString(), storageAccount.Credentials)
_ServiceContext.IgnoreResourceNotFoundException = True
_ServiceContext.MergeOption = MergeOption.NoTracking
' Create the tables
' In this case, just a single table.
storageAccount.CreateCloudTableClient().CreateTableIfNotExist(<table name>)
End Sub
Fiddler没有透露任何有趣的内容。
我没有想法......
再次,非常感谢任何帮助。
干杯
答案 0 :(得分:0)
删除_ServiceContext.MergeOption = MergeOption.NoTracking
。这使DataServiceContext
无法跟踪实体。