Erro de Insert EF MVC

alfinete

Power Member
Boas tardes

estou com este erro a quando fasso uma gravação , e depois não grava
este campo é uma foreign da tabela operador


The column name 'OperatorID' is specified more than once in the SET clause or column list of an INSERT.
A column cannot be assigned more than one value in the same clause.
Modify the clause to make sure that a column is updated only once.
If this statement updates or inserts columns into a view, column aliasing can conceal the duplication in your code.

RequestMap.cs
________________________________________
Código:
using hnb.dmobile.entities.Models;
using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace hnb.dmobile.data.Models.Mapping
{
  public class RequestMap : EntityTypeConfiguration<Request>
  {
  public RequestMap()
  {
  // Primary Key
  this.HasKey(t => t.ID);

  // Properties
  this.Property(t => t.CardNumber)
  .HasMaxLength(15);

  this.Property(t => t.CardIMEI)
  .HasMaxLength(20);

  this.Property(t => t.CardMBReference)
  .HasMaxLength(10);

  this.Property(t => t.MigrationSIM)
  .HasMaxLength(20);

  this.Property(t => t.InvoiceNumber)
  .HasMaxLength(20);

  // Table & Column Mappings
  this.ToTable("Request");
  this.Property(t => t.ID).HasColumnName("ID");
  this.Property(t => t.RequestTypeID).HasColumnName("RequestTypeID");
  this.Property(t => t.RequestStatusID).HasColumnName("RequestStatusID");
  this.Property(t => t.EmployeeID).HasColumnName("EmployeeID");
  this.Property(t => t.CardExisting).HasColumnName("CardExisting");
  this.Property(t => t.CardNumber).HasColumnName("CardNumber");
  this.Property(t => t.CardIMEI).HasColumnName("CardIMEI");
  this.Property(t => t.CardMBReference).HasColumnName("CardMBReference");
  this.Property(t => t.CardTypeID).HasColumnName("CardTypeID");
  this.Property(t => t.MigrationOperatorID).HasColumnName("MigrationOperatorID");
  this.Property(t => t.MigrationSIM).HasColumnName("MigrationSIM");
  this.Property(t => t.IsNewDevice).HasColumnName("IsNewDevice");
  this.Property(t => t.IsEvoucher).HasColumnName("IsEvoucher");
  this.Property(t => t.OperatorID).HasColumnName("OperatorID");

  this.Property(t => t.InternalOperatorID).HasColumnName("OperatorId");

  this.Property(t => t.DeviceID).HasColumnName("DeviceID");
  this.Property(t => t.ColorID).HasColumnName("ColorID");
  this.Property(t => t.Value).HasColumnName("Value");
  this.Property(t => t.PlanOperatorID).HasColumnName("PlanOperatorID");
  this.Property(t => t.InvoiceNumber).HasColumnName("InvoiceNumber");
  this.Property(t => t.Subvention).HasColumnName("Subvention");
  this.Property(t => t.SubmitDate).HasColumnName("SubmitDate");
  this.Property(t => t.ProcurementDate).HasColumnName("ProcurementDate");
  this.Property(t => t.DeliveryDate).HasColumnName("DeliveryDate");
  this.Property(t => t.PickedDate).HasColumnName("PickedDate");
  this.Property(t => t.Historic).HasColumnName("Historic");
  this.Property(t => t.MigratedRequest).HasColumnName("MigratedRequest");
  this.Property(t => t.MigratedRequestAcceptNewOperator).HasColumnName("MigratedRequestAcceptNewOperator");
  this.Property(t => t.MigratedRequestNewEquipment).HasColumnName("MigratedRequestNewEquipment");
  this.Property(t => t.MigratedRequestOldRequestID).HasColumnName("MigratedRequestOldRequestID");
  this.Property(t => t.AllDocumentsReceived).HasColumnName("AllDocumentsReceived");

  // Relationships
  this.HasRequired(t => t.CardType)
  .WithMany(t => t.Requests)
  .HasForeignKey(d => d.CardTypeID);
  this.HasOptional(t => t.Color)
  .WithMany(t => t.Requests)
  .HasForeignKey(d => d.ColorID);
  this.HasOptional(t => t.Device)
  .WithMany(t => t.Requests)
  .HasForeignKey(d => d.DeviceID);
  this.HasRequired(t => t.Employee)
  .WithMany(t => t.Requests)
  .HasForeignKey(d => d.EmployeeID);
  this.HasRequired(t => t.Plan_Operator)
  .WithMany(t => t.Requests)
  .HasForeignKey(d => d.PlanOperatorID);
  this.HasRequired(t => t.RequestStatus)
  .WithMany(t => t.Requests)
  .HasForeignKey(d => d.RequestStatusID);
  this.HasRequired(t => t.RequestType)
  .WithMany(t => t.Requests)
  .HasForeignKey(d => d.RequestTypeID);
  //this.HasRequired(t => t.InternalOperator)
  //  .WithMany(t => t.Requests)
  //  .HasForeignKey(d => d.OperatorID);

   

  }
  }
}

Request.cs
____________________________________________________________________
Código:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace hnb.dmobile.entities.Models
{
  public partial class Request : Repository.Pattern.Ef6.Entity
  {
  public int ID { get; set; }
  public int RequestTypeID { get; set; }
  public int RequestStatusID { get; set; }
  public int EmployeeID { get; set; }
  public bool CardExisting { get; set; }
  public string CardNumber { get; set; }
  public string CardIMEI { get; set; }
  public string CardMBReference { get; set; }
  public int CardTypeID { get; set; }
  public Nullable<int> MigrationOperatorID { get; set; }
  //  public int InternalOperator_ID { get; set; }
   
  public int InternalOperatorID { get; set; }

  public string MigrationSIM { get; set; }
  public bool IsNewDevice { get; set; }
  public bool IsEvoucher { get; set; }
  public Nullable<int> DeviceID { get; set; }
  public Nullable<int> ColorID { get; set; }
  public Nullable<decimal> Value { get; set; }
  public int PlanOperatorID { get; set; }
  public string InvoiceNumber { get; set; }
  public Nullable<bool> Subvention { get; set; }
  public System.DateTime SubmitDate { get; set; }
  public Nullable<System.DateTime> ProcurementDate { get; set; }

  // [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "yyyy-MM-dd")]
  public Nullable<System.DateTime> DeliveryDate { get; set; }
  public Nullable<System.DateTime> PickedDate { get; set; }
  public bool Historic { get; set; }
  public bool MigratedRequest { get; set; }
  public Nullable<int> MigratedRequestAcceptNewOperator { get; set; }
  public Nullable<int> MigratedRequestNewEquipment { get; set; }
  public Nullable<int> MigratedRequestOldRequestID { get; set; }
  public bool AllDocumentsReceived { get; set; }
  public int OperatorID { get; set; }

  public virtual CardType CardType { get; set; }
  public virtual Color Color { get; set; }
  public virtual Device Device { get; set; }
  public virtual Employee Employee { get; set; }
  public virtual Operator InternalOperator { get; set; }
  //public virtual Operator MigrationOperator { get; set; }
  public virtual Plan_Operator Plan_Operator { get; set; }
  public virtual RequestStatus RequestStatus { get; set; }
  public virtual RequestType RequestType { get; set; }
  // public virtual ManagementAccounts ManagementAccounts { get; set; }
  }
}

metodo Create Request ESTA no request service rebenta no save changes
_unitOfWork.SaveChanges();
________________________________________________________
Código:
  public bool CreateRequest(Request request)
  {
  try
  {
  // bussiness rules
  var oldRequest = GetEmployeeRequestByType(request.Employee.Number, request.RequestTypeID);

  bool canRequestNewProcess = oldRequest == null ||
  (oldRequest.RequestStatus.Code != (int)REQUESTSTATUSCODE.SUBMETIDO
  || oldRequest.MigratedRequest);


  if (canRequestNewProcess)
  {
  // special case for migrated records
  if (oldRequest != null && oldRequest.MigratedRequest)
  {
  if (oldRequest.MigratedRequestAcceptNewOperator != 2)
  {
  oldRequest.RequestStatusID = _unitOfWork.Repository<RequestStatus>()
  .Query(rs => rs.Code == (int)REQUESTSTATUSCODE.PROCESSO_CONCLUIDO)
  .Select(rs => rs.ID)
  .Single();
  }

  CopyRequest(ref oldRequest, ref request);
  }


  var submited = _requestStatusRepository
  .Query(rs => rs.Code == (int)REQUESTSTATUSCODE.SUBMETIDO)
  .Select()
  .Single();

  request.RequestStatusID = submited.ID;
  CheckBusinessRules(request);

  request.SubmitDate = DateTime.Now;

  if (oldRequest != null && oldRequest.MigratedRequest)
  _requestRepository.Update(oldRequest);

  _requestRepository.Insert(request);

  _unitOfWork.SaveChanges();
  }
  else
  {
  _logger.Error("Can't create request because he already has." + Environment.NewLine +
  "Employee Number=" + request.Employee.Number + ", RequestTypeID=" + request.RequestTypeID +
  ", oldRequestID=" + oldRequest.ID);
  return false;
  }
  }
  catch (DbEntityValidationException dve)
  {
  foreach (var entity in dve.EntityValidationErrors)
  {
  foreach (var error in entity.ValidationErrors)
  {
  _logger.Error("while creating new request for ueser " + request.Employee.Number + Environment.NewLine +
  "erro: " + error.ErrorMessage + " PropertyName: " + error.PropertyName);
  }
  }
  }
  catch (Exception ex)
  {
  _logger.Error(ex, "while CreateRequest.");
  return false;
  }

  return true;
  }


agradecia uma ajuda
 
Última edição:
Back
Topo