实体发送到服务器问题

发布于 2024-11-07 21:22:15 字数 912 浏览 0 评论 0原文

在客户端,我将所有相关实体(导航属性)添加到我的主要实体,并将其附加到列表并调用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

剪不断理还乱 2024-11-14 21:22:15

我不确定你在这里做什么。但是,如果我想添加东西,我会这样做并且它有效:

Context = new DomainContext();

var customer = new Customer() { /* ... */ };
var order = new Order() { Customer = customer, /* ... */ };

Context.Customers.Add(customer);
Context.Orders.Add(order);

如果您喜欢其他方法,您也可以这样做:

var customer = new Customer() { /* ... */ };
var order = new Order { /* ... */ };

customer.Orders.Add(order);
Context.Customers.Add(customer);

现在您只需提交:

var submitOperation = Context.SubmitChanges();
submitOperation.Completed += // [...]

希望这会有所帮助。

I'm not sure what you are doing here. But if I want to add stuff I do it like this and it works:

Context = new DomainContext();

var customer = new Customer() { /* ... */ };
var order = new Order() { Customer = customer, /* ... */ };

Context.Customers.Add(customer);
Context.Orders.Add(order);

If you like the other approach though, you can do that too like this:

var customer = new Customer() { /* ... */ };
var order = new Order { /* ... */ };

customer.Orders.Add(order);
Context.Customers.Add(customer);

Now you just submit:

var submitOperation = Context.SubmitChanges();
submitOperation.Completed += // [...]

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文