title: Entity Framework code-first approach one-to-one fluent api mapping
body: <p>I'm trying to create a one-to-one mapping with Entity Framework code-first (including fluent API mapping) approach. This is the first time I'm using code first approach.</p>
  
  <p>When I run the <code>UpdateTaskCompleted()</code> method, it throws the following exception:</p>
  
  <blockquote>
    <p>Operand type clash: uniqueidentifier is incompatible with int</p>
  </blockquote>
  
  <p>I suspect that I'm doing something wrong in fluent API mapping.</p>
  
  <pre><code>[Table("tblSession")]
  public partial class tblSession
  {
          [Key]
          public Guid SessionId { get; set; }
  
          [Required]
          public bool IsActive { get; set; }
  
          public tblTaskDetail tblTaskDetail { get; set; }
  }
  
  [Table("tblTaskDetail")]
  public partial class tblTaskDetail
  {
      [Key]
      public int TaskDetailID { get; set; }
  
      public Guid? SessionID { get; set; }
  
      [Required]
      [StringLength(50)]
      public string TaskStatus { get; set; }
  
      [ForeignKey("SessionID")]
      public tblSession tblSession { get; set; }
  }
  
  public class RequestSession
  {
      [Key]
      public Guid SessionId { get; set; } 
      public bool IsActive { get; set; }
      public TaskDetail TaskDetail { get; set; }
  }
  
  public class TaskDetail
  {
      [Key]
      public int TaskDetailID { get; set; }
      public Guid? SessionID { get; set; }
      public string TaskStatus { get; set; }
      public RequestSession RequestSession { get; set; }
  }
  
  public class TaskDetailMapper:EntityTypeConfiguration&lt;TaskDetail&gt;
  {
      public TaskDetailMapper()
      {
          this.ToTable("tblTaskDetail");
          this.HasKey(hk =&gt; hk.TaskDetailID);
          HasRequired&lt;RequestSession&gt;(a =&gt; a.RequestSession)
                            .WithRequiredPrincipal(o =&gt; o.TaskDetail).Map(m =&gt; m.MapKey("SessionID"));
  
          this.Property(o =&gt; o.TaskStatus).HasColumnName("TaskStatus");
      }
  }
  
  public class RequestSessionMapper : EntityTypeConfiguration&lt;RequestSession&gt;
  {
      public RequestSessionMapper()
      {
          // Table &amp; Column Mappings
          this.ToTable("tblSession");
  
          //Primary key
          this.HasKey&lt;Guid&gt;(hk =&gt; hk.SessionId);
          this.Property(t =&gt; t.SessionId).HasColumnName("SessionId");
          this.Property(t =&gt; t.IsActive).HasColumnName("IsActive");
      }
  }
  
  public partial class WarehouseAPIContext : DbContext
  {
      public WarehouseAPIContext(): base("name=WarehouseAPIContext")
      {
      }
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {           
          modelBuilder.Configurations.Add(new RequestSessionMapper());
          modelBuilder.Configurations.Add(new TaskDetailMapper());
      }
  }
  
  public TaskDetail UpdateTaskCompleted(TaskDetail entity)
  {
          try
          {
              var entry = dbSet.Find(entity.TaskDetailID);
              entry.TaskStatus = entity.TaskStatus;
  
              entity.RequestSession = new RequestSession()
              {
                  IsActive = false
              };
  
              _context.SaveChanges(); 
  
              return entity;
          }
          catch (Exception ex)
          {
              throw ex;
          }
  }
  </code></pre>