Duplicate entity getting created

Jun 8, 2015 at 7:50 PM
Hi,

I've 2 entities, Employee, Department. I added 2 departments (IT, Science) into the database. While i add a new employee with an existing department, an new department with name "IT" is also getting added to DB.
Is there i'm doing something wrong? Please suggest

Repository<Department> repo = new Repository<Department>();
    var result = repo.Find(a => a.Name == "IT");

    UnitOfWork uow = new UnitOfWork(); 

    Employee e = new Employee()
    {
        EmployeeId = 1,
        FirstName = "Sudip",
        LastName = "P",
    };
    e.Department = result.Entities.First();
    repoe.Add(e);

//////////////////////////////////////////
public partial class Department
{
public Department()
{
    this.Employees = new HashSet<Employee>();
}

public int DepartmentId { get; set; }
public string Name { get; set; }

public virtual ICollection<Employee> Employees { get; set; }
}
public partial class Employee
{
public int EmployeeId { get; set; }
public int DepartmentId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }

public virtual Department Department { get; set; }
}