0

次のコードがあり、AssignmentID と ToDoAssignmentID を同じ値に設定したいと考えています。AssignmentID を workOrder.AssignmentID に設定すると問題なく動作しますが、ToDoAssignmentID を workOrder.AssignmentID に設定すると、ToDoAssignmentID が 0 に設定されます。なぜですか?

workOrder.ClientID = this.Client.ClientID;
workOrder.AssignmentID = this.WorkOrderID;
workOrder.AssignmentNumber = this.GetNextWorkOrderNumber(this.Client);
workOrder.CustomerID = this._CustomerID;
workOrder.DateCreated = this.Created;
workOrder.DatoAvtaltStart = this.AgreedStart == DateTime.MinValue ? new DateTime().MinSDTValue() : this.AgreedStart;
workOrder.DatoAvtaltSlutt = this.AgreedEnd == DateTime.MinValue ? new DateTime().MinSDTValue() : this.AgreedEnd;
workOrder.DateStopped = this.Ended == DateTime.MinValue ? new DateTime().MinSDTValue() : this.Ended;
workOrder.CreatedByEmployeeID = this._CreatedByEmployeeID;
workOrder.ResponsibleEmployeeID = this._ResponsibleEmployeeID;
workOrder.KoordinatorAnsattId = this._CoordinatorEmployeeID;
workOrder.Description = this.Description;
workOrder.Notes = this.Notes;
workOrder.EstimertTimerFra = this.EstimatedHoursFrom;
workOrder.EstimertTimerTil = this.EstimatedHoursTo;
workOrder.EstimatedBillingDate = this.EstimatedBillingDate;
workOrder.Priority = (byte)this.Priority;
workOrder.OBS = this.OBS;
workOrder.CustomerReference = this.CustomersReference;
workOrder.InterntOrdrenr = this.InternalOrderNumber;
workOrder.EksterntOrdrenr = this.ExternalOrderNumber;
workOrder.AssignmentStatusID = this.WorkOrderStatusID;

foreach (var activity in this.Activities)
{
    var ProductID = 0;

    try
    {
        ProductID = activity.Product.ProductID;
    }
    catch (Exception ex)
    {
    }

    workOrder.Activities.Add(new Activity()
    {
        ActivityID = activity.ActivityID,
        ClientID = activity.Client.ClientID,
        AssignmentID = workOrder.AssignmentID,
        Description = activity.Description,
        Notes = activity.Notes,
        IsBillable = activity.Billable,
        Priority = (byte)activity.Priority,
        ActivityTypeID = activity.ActivityType.TypeID,
        PerformedByEmployeeID = activity.PerformedByEmployee.EmployeeID,
        ProductID = ProductID,
        ToDo = activity.IsPlanned,
        ToDoAssignmentID = workOrder.AssignmentID,
        ToDoCustomerID = workOrder.CustomerID
    });
}

workOrderContext.SubmitChanges();
4

1 に答える 1