0

I have this weird issue wherein when I add new values to database. suppose to be I expected also that the navigational properties will have data after UnitOfWork.SaveChanges().

Heres my model:

    [Column("Client_ID"), Key]
    public int ClientID{ get; set; }

    [Column("Employee_ID"), Required]
    public int EmployeeID { get; set; }

    [ForeignKey("EmployeeID")]
    public virtual Employee201 Employee { get; set; }

On save changes only the ClientID updated the values not the Employee with foreign key. Am I lacking something here?

Repository method

    public Client Create(Client  client )
    {
        if (client != null)
        {
            GetDbSet<Client  >().Add(client );
            UnitOfWork.SaveChanges();
        }
        return client ;
    }

Update

Now i found the issue. when im adding new data im using new Client() this result to entity type only and not proxy type. Is there a way to convert this when im using new Client() that it should always be proxy type?

Rashid
  • 1,700
  • 1
  • 23
  • 56

1 Answers1

0

What is Employee201 ?

I always write this way And it works.

(Clients is your dbset. public System.Data.Entity.DbSet< Client> Clients { get; set; })

UnitOfWork = new DataBaseContext();

UnitOfWork.Clients.Add(client);

UnitOfWork.SaveChanges();

Mahrooy
  • 396
  • 1
  • 3
  • 7