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

Navigation properties without foreign keys #20744

Closed
Palpie opened this issue Apr 24, 2020 · 1 comment
Closed

Navigation properties without foreign keys #20744

Palpie opened this issue Apr 24, 2020 · 1 comment

Comments

@Palpie
Copy link

Palpie commented Apr 24, 2020

I want to be able to use Include without a database relation. This is possible using LINQ Join.

Right now the best example I have is where I want to be able to get log items when I get something that has been logged, but my log entity doesn't have relations to every other entity.

If I can add a navigation property wihtout a foreign key it would be clear to everyone that there is a relationship between the entities and it would be easier to work with includes than joins because how they are "joined" has already been set up in the DbContext configuration.

Example configuration for IEntityTypeConfiguration<User>:

builder
    .HasMany(user => user.Logs)
    .HasRelationWithoutForeignKey(user => new { Type = "User", Id = user.Id },
                                  log => new { Type = log.Entity, Id = log.EntityId });

Used in code just like navigations properties today:

_dbContext.Users
          .Include(u => u.Logs)
          .Where(u => u.Id == userId)
          .FirstOrDefault();
@ajcvickers
Copy link
Member

Duplicate of #15854

@ajcvickers ajcvickers marked this as a duplicate of #15854 Apr 24, 2020
mariusGundersen added a commit to bardarswingclub/MemberService that referenced this issue Nov 29, 2021
Until dotnet/efcore#20744 is implemented this isn't possible, unfortunately

This fixes #62
@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

2 participants