Link to home
Start Free TrialLog in
Avatar of RBS
RBS

asked on

EF Create Employee Table with Hash Set - Reports To

Hi:

I would like to create the following table from Entity Framework:

CREATE TABLE [dbo].[Employees] (
    [EmployeeID]      INT            IDENTITY (1, 1) NOT NULL,
    [LastName]        NVARCHAR (20)  NOT NULL,
    [FirstName]       NVARCHAR (10)  NOT NULL,
    [ReportsTo]       INT            NULL,
    CONSTRAINT [PK_Employees] PRIMARY KEY CLUSTERED ([EmployeeID] ASC),
    CONSTRAINT [FK_Employees_Employees] FOREIGN KEY ([ReportsTo]) REFERENCES [dbo].[Employees] ([EmployeeID])

);

GO
CREATE NONCLUSTERED INDEX [LastName]
    ON [dbo].[Employees]([LastName] ASC);

Open in new window


This is what I have so far - but it is creating an extra field:

public class Employee
    {
        public Employee()
        {
            Employees1 = new HashSet<Employee>();
        }

        public int EmployeeID { get; set; }

        [Required]
        [StringLength(20)]
        public string LastName { get; set; }

        [Required]
        [StringLength(10)]
        public string FirstName { get; set; }


        public int? ReportsTo { get; set; }

        public virtual ICollection<Employee> Employees1 { get; set; }

        public virtual Employee Employee1 { get; set; }

    }

Open in new window


Any help fixing this greatly appreciated.

RBS
ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RBS
RBS

ASKER

Hi:

I ended up figuring this out myself - needed to specify the foreign key using on model creating - thanks for the follow up.

RBS