实体发送到服务器问题
在客户端,我将所有相关实体(导航属性)添加到我的主要实体,并将其附加到列表并调用SubmitChange。但在服务器端,所有相关实体都丢失了!
代码:
客户端:
DomainService1 domainService1= new DomainService1();
.
.
.
WorkCode newWorkCode = new WorkCode();
newWorkCode.Date = DateTime.Now;
.
.
.
for(Work item in WorkList)
{
newWorkCode.Works.Add(item)
}
.
.
.
domainService1.WorkCodes.Attach(newWorkCode);
domainService1.InsertWorkCode(newWorkCode);
dsMaintenance.SubmitChanges(submitOperation =>
{
if (!submitOperation.HasError)
{
}
},
null);
服务器:
[Update(UsingCustomMethod = true)]
public void InsertWorkCode(WorkCode workCode)
{
//////// workCode.Works = 0 ///////////////////
this.ObjectContext.WorkCodes.AddObject(workCode);
}
On the client-side I add all related entities (navigation properties) to my main entity and attach it to the list and call SubmitChange. But on the server-side, all related entities are missing!
Code:
Client:
DomainService1 domainService1= new DomainService1();
.
.
.
WorkCode newWorkCode = new WorkCode();
newWorkCode.Date = DateTime.Now;
.
.
.
for(Work item in WorkList)
{
newWorkCode.Works.Add(item)
}
.
.
.
domainService1.WorkCodes.Attach(newWorkCode);
domainService1.InsertWorkCode(newWorkCode);
dsMaintenance.SubmitChanges(submitOperation =>
{
if (!submitOperation.HasError)
{
}
},
null);
Server:
[Update(UsingCustomMethod = true)]
public void InsertWorkCode(WorkCode workCode)
{
//////// workCode.Works = 0 ///////////////////
this.ObjectContext.WorkCodes.AddObject(workCode);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你在这里做什么。但是,如果我想添加东西,我会这样做并且它有效:
如果您喜欢其他方法,您也可以这样做:
现在您只需提交:
希望这会有所帮助。
I'm not sure what you are doing here. But if I want to add stuff I do it like this and it works:
If you like the other approach though, you can do that too like this:
Now you just submit:
Hope this helps.