Search code examples
c#azuretelerikopenaccess

Telerik DataAccess (OpenAccess) nullable foreign key performance


We are looking for help from people who use Telerik DataAccess ORM. Recently, we encountered a big performance issue with nullable foreign key.

When we assign value to nullable int foreign key property (without SaveChanges) - Telerik makes several calls to the database and do some strange work. We used dotTrace and found that there are a lot of SQL DataReader calls and some strange string/DateTime/Enum/... converters. This issue only appears when we set value to the property, get is working ok.

A little bit about our environment. We tried to create an empty console app. The same strange code is invoked, but it is much faster in local environment - ~60ms for small Entity and local db. For big entity it is ~ 1.5 sec, but in our production server that uses Azure Sql DB - it is from 10 to 50 second.

Remark: we tried to load and set object directly, without using foreign key, it does not help.

public class Entity
{
    public int? ParentId { get; set; } // Wee see this issue when we set value to the ParentId or Parent property. SaveChanges is not called.

    public Parent Parent { get; set; }
}

Here you can find the dotTrace call stack.


Solution

  • Finally, I solved this issue. I want to warn everyone who uses IsManaged configuration. Every time when you set ParentId or Parent entity, ALL children with specified ParentId are loaded into memory. Even if lazy-load is enabled.

    Telerik agree that this behavior can be optimized, but they don't want to make any changes because of backward compatibility.