Skip to content

EF7 Fluent API: Self Referencing Tables #1467

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
WillBaldwin opened this issue Jan 24, 2015 · 4 comments
Closed

EF7 Fluent API: Self Referencing Tables #1467

WillBaldwin opened this issue Jan 24, 2015 · 4 comments

Comments

@WillBaldwin
Copy link

It appears as if EF7 uses all new Fluent API. Does anyone know where I might find more info? I'd like to implement self referencing tables with EF7.

public class Employee
{
public int EmployeeId //minus the gets and sets
public Employee Manager //maps to the manager's Employee
public int ManagerId //maps to the manager's Employee.EmployeeId
public string Name
public Employees
}

//EF7 Fluent API does not seem to support the following.. perhaps there is a translation?
HasOptional(x => x.Manager) //new Fluent API property maybe??
.WithMany(x => x.Employees) //new Fluent API .OneToMany
.HasForeignKey(x => x.ManagerId) //new Fluent API ForeighKey
.WillCascadeOnDelete(false); //new Fluent API property maybe??

@AndriySvyryd
Copy link
Member

The EF 7 equivalent is
.Entity()
.HasOne(x => x.Manager)
.WithMany(x => x.Employees)
.ForeignKey(x => x.ManagerId)
.Required(false);

Cascade on delete is not supported yet

@WillBaldwin
Copy link
Author

The following are not resolving for me, I assume they are introduced in later builds of EF7 after "7.0.0-beta1", is that correct?

.HasOne(x => x.Manager)
.WithMany(x => x.Employees)

@rowanmiller
Copy link
Contributor

Correct, they are currently in nightly builds. Here is some info on using the latest builds https://github.com/aspnet/EntityFramework/wiki/Getting-Started-with-Nightly-Builds.

@weitzhandler
Copy link
Contributor

@rowanmiller @AndriySvyryd
Alright, no problems with storing the data, but is there a way to retrieve a hierarchy of depth n?
#3241

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants