RBS
asked on
EF Create Employee Table with Hash Set - Reports To
Hi:
I would like to create the following table from Entity Framework:
This is what I have so far - but it is creating an extra field:
Any help fixing this greatly appreciated.
RBS
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);
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; }
}
Any help fixing this greatly appreciated.
RBS
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I ended up figuring this out myself - needed to specify the foreign key using on model creating - thanks for the follow up.
RBS