Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

multiple table to one foreign key relationship #10620

Closed
ErliSoares opened this issue Dec 28, 2017 · 3 comments
Closed

multiple table to one foreign key relationship #10620

ErliSoares opened this issue Dec 28, 2017 · 3 comments

Comments

@ErliSoares
Copy link

I know it's not a good practice, but I'm working on a project that contains "foreign key" referencing more than one table, the whole bank is this way, I wanted to know if the entity framework supports this type of relationship, so I studied and researched is not supported, if they have a solution, it helps a lot, I'm migrating to the entity framework. But without this feature I can not migrate, an example below:
Data Base:

Tasks
- Id
- SourceId
- TypeSource //Used to set the connection
- Description

OrderService
- Id
- Description

Schedule
- Id
- Description

Code:

ITaskSource
- Id -> int
- Description

Tasks
- Id -> int
- Source -> ITaskSource
- TypeSource -> string //Used to set the connection
- Description -> string

OrderService : ITaskSource
- Id -> int
- Description -> string

Schedule : ITaskSource
- Id -> int
- Description -> string
@Tarig0
Copy link

Tarig0 commented Jan 2, 2018

After taking a closer look at this seems to be me like you have 2 types of tasks

OrderTask, ScheduleTask -> Task

Abstract Task

  • Id -> int
  • Description -> string

OrderTask -> Task

  • Source -> OrderService

ScheduleTask -> Task

  • Source -> Schedule
modelBuilder.Entity<Task>().HasDiscriminator("TaskSource").HasValue<ScheduleTask>("Schedule").HasValue<OrderTask>("Order")

@ErliSoares
Copy link
Author

As soon as I get the time, I'll test, thank you.

@ajcvickers
Copy link
Member

@ErliSoares Looks like you are asking for polymorphic relationships, which is being tracked by #7623

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants