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

0

关键不是考虑数据库风格,而是 ORM 风格。

因此,您无需设置键,而是分配实体。

所以改变

ToDoAssignmentID = workOrder.AssignmentID

到(最可能的表名猜测,检查实体的定义)以下实体分配

ToDoAssignment = workOrder

这也将在 SubmitChanges 期间处理。

于 2013-06-18T18:09:58.237 回答