Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Fix sub-inheritance mapping attributes generation#347

Merged
MaceWindu merged 2 commits into
linq2db:masterfrom
tarasverq:sub-inheritance
Oct 12, 2023
Merged

Fix sub-inheritance mapping attributes generation#347
MaceWindu merged 2 commits into
linq2db:masterfrom
tarasverq:sub-inheritance

Conversation

@tarasverq

Copy link
Copy Markdown
Contributor

Hello.

This PR fixes generation of InheritanceMappingAttribute when you have stronger hierarchy than just one child.

Example

Let's pretend we have such class hierarchy:

public class WithInheritance
{
  public int Id { get; set; }
  public string Discriminator { get; set; } = null!;
}

public class WithInheritanceA : WithInheritance { }

public class WithInheritanceA1 : WithInheritanceA { }

public class WithInheritanceA2 : WithInheritanceA { }

Then when you try to get all WithInheritanceA objects linq2db would create this query:

SELECT
  t1."Id",
  t1."Discriminator"
FROM
  "WithInheritance" t1
WHERE
  t1."Discriminator" = 'WithInheritanceA'

But that's wrong: inherited entities WithInheritanceA1 and WithInheritanceA2 also should be included in query.

(t1."Discriminator" = 'WithInheritanceA'  OR
 t1."Discriminator" = 'WithInheritanceA1' OR 
 t1."Discriminator" = 'WithInheritanceA2')

My PR fixes that problem by finding all relations between inherited types and then adding it to collection of mapping attributes. Unit test also included, was tested on PgSql

@MaceWindu

Copy link
Copy Markdown
Contributor

Thanks!

@MaceWindu
MaceWindu merged commit 7d8ffea into linq2db:master Oct 12, 2023
MaceWindu pushed a commit that referenced this pull request Oct 13, 2023
* 1. Fix sub-inheritance mapping attributes generation

* 1. Simplification

(cherry picked from commit 7d8ffea)
MaceWindu pushed a commit that referenced this pull request Oct 13, 2023
* 1. Fix sub-inheritance mapping attributes generation

* 1. Simplification

(cherry picked from commit 7d8ffea)
(cherry picked from commit 8f7d7b5)
MaceWindu pushed a commit that referenced this pull request Oct 13, 2023
* 1. Fix sub-inheritance mapping attributes generation

* 1. Simplification

(cherry picked from commit 7d8ffea)
(cherry picked from commit 8f7d7b5)
(cherry picked from commit 24f2361)
MaceWindu pushed a commit that referenced this pull request Oct 13, 2023
* 1. Fix sub-inheritance mapping attributes generation

* 1. Simplification

(cherry picked from commit 7d8ffea)
(cherry picked from commit 8f7d7b5)
(cherry picked from commit 24f2361)
(cherry picked from commit 4383a1d)

# Conflicts:
#	Source/LinqToDB.EntityFrameworkCore/EFCoreMetadataReader.cs
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants