This is a migrated thread and some comments may be shown as answers.

Optmizing JOIN clauses by removing references to abstract types

3 Answers 20 Views
Data Access Free Edition
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Catalin
Top achievements
Rank 1
Catalin asked on 20 Aug 2015, 12:49 PM

Hi,

let's take a simple example mapped with flat inheritance:

public abstract class Animal
  {
    public int Id { get; set; }
    public string Name { get; set; }
    public Home Home { get; set; }
  }
 
  public class Dog : Animal
  {
    public int Age { get; set; }
  }
 
  public class Cat : Animal
  {
    public int Lives { get; set; }
  }
 
  public class Home
  {
    public int Id { get; set; }
    public string Name { get; set; }
    public Home() { Animals = new List<Animal>(); }
    public IList<Animal> Animals { get; set; }
  }

 

For accessing the property home.Animals the generated SQL statement would be:

SELECT b.[Id] COL1, b.[voa_class] COL2, b.[HomeId] COL3, b.[nme] COL4, b.[Lives] COL5, b.[Age] COL6
FROM [Home] a LEFT JOIN [Animal] AS b
  ON (a.[Id] = b.[HomeId] AND (b.[voa_class] IN ('Animal', 'Dog', 'Cat')))
WHERE a.[Id] = @p0

 

Here is something I don't understand. Why is the 'Animal' appearing in the JOIN clause?

The Animal class is abstract which means there will never be any objects of that type. Indeed in the table there are no other entries but 'Dog' and'Cat'.

I think the ORM should optimize the statement by removing the abstract types from the JOIN clauses.

 

3 Answers, 1 is accepted

Sort by
0
Boris Georgiev
Telerik team
answered on 24 Aug 2015, 11:09 AM
Hello Catalin,

When you are using Flat inheritance, Telerik Data Access will generate only one table for all of the classes which are part of the inheritance and the table will be for the base class. This is why you are seeing the Animal table in the join clause. For more information about Inheritance please refer to this article: http://docs.telerik.com/data-access/developers-guide/code-only-mapping/inheritance/fluent-mapping-inheritance-overview.

I hope that helps.

Regards,
Boris Georgiev
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
0
Catalin
Top achievements
Rank 1
answered on 07 Sep 2015, 07:36 AM

Hi Boris,

I actually mind the string 'Animal' in the IN enumeration by the ON expression.

Regards,
Catalin

0
Viktor Zhivkov
Telerik team
answered on 10 Sep 2015, 08:34 AM
Hello Catalin,

Thank you for your feedback.
This is a nice suggestion for optimization, but I am curious if you are seeing any (significant) performance penalty because of the extra join clause.
As far as I know there is no way to explicitly tell our mapping that a class is an abstract one so I guess this is the reason why we are adding it together with all derived ones.
If we are able to optimize our LINQ translation in the recommended way I will make sure to contact you back.

Regards,
Viktor Zhivkov
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Tags
Data Access Free Edition
Asked by
Catalin
Top achievements
Rank 1
Answers by
Boris Georgiev
Telerik team
Catalin
Top achievements
Rank 1
Viktor Zhivkov
Telerik team
Share this question
or