使用ADO.NET数据服务时保存实体错误 [英] Save entity error when using ADO.NET Data Service
问题描述
我尝试使用以下代码来保存数据异步:
NorthwindEntities svcx = new NorthwindEntities(new Uri(" NorthwindDataService.svc",UriKind.Relative));
try
{
svcx.UpdateObject(_people); //在这一行,得到错误
svcx.BeginSaveChanges(delegate(IAsyncResult result)
(DataServiceRequestException ex)
{
Debug.WriteLine(" OnSaveChangesCompleted Error:" + ex.Response.ToString());
}
},_poeple);
}
catch(DataServiceRequestException ex)
{
Debug.WriteLine(" OnUpdate Error:" + ex.Response.ToString());
但是当运行转到行svcx.UpdateObject(_people)时; ,我收到如下错误:
System.Data.Services.Client中发生了'System.ArgumentException'类型的异常,但未在用户代码中处理
其他信息:上下文是目前没有跟踪实体。
它有什么问题?如何解决?
您好,
在UpdateObject调用之前需要这一行:
svcx.AttachTo(" NameOfThEntitySet",_ people);& nbsp;
I tried to use following code to save data async:
NorthwindEntities svcx = new NorthwindEntities(new Uri("NorthwindDataService.svc", UriKind.Relative));
try
{
svcx.UpdateObject(_people); //at this line, get error
svcx.BeginSaveChanges(delegate(IAsyncResult result)
{
try
{
svcx.EndSaveChanges(result);
}
catch (DataServiceRequestException ex)
{
Debug.WriteLine("OnSaveChangesCompleted Error: " + ex.Response.ToString());
}
}, _poeple);
}
catch (DataServiceRequestException ex)
{
Debug.WriteLine("OnUpdate Error: " + ex.Response.ToString());
}
But when the running went to the line svcx.UpdateObject(_people); , I got error as below:
An exception of type 'System.ArgumentException' occurred in System.Data.Services.Client but was not handled in user code
Additional information: The context is not currently tracking the entity.
What's wrong with it? how to fix it?解决方案Hi,
You need this line before the UpdateObject call :
svcx.AttachTo("NameOfThEntitySet",_people);
这篇关于使用ADO.NET数据服务时保存实体错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文