엔티티가 서버 문제로 보냅니다
-
14-11-2019 - |
문제
클라이언트 측에서 i 모든 엔티티 엔티티 에 모두 (탐색 속성)을 추가하고 목록에 첨부하고 submittange .그러나 서버 측에서는 모든 관련 엔티티가 없습니다!
코드 :
클라이언트 :
.
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);
}
해결책
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.