AutoQuery multiple left joins of the same table

Hi

Simple master-detail relationship

public class SomeData
{
  [AutoIncrement] public int Id {get;set;}
  ....
  [ForeignKey(typeof(User)] public int CreatedById {get;set;}
  [ForeignKey(typeof(User)] public int? ModifiedById {get;set;}
}

public class User
{
  [AutoIncrement] public int Id {get;set;}
  [Required] public string Name {get;set;}
}

Autoquery output should be something like:

public class DataResult
{
  public int Id {get;set;}
  ...
  public string CreatedByName {get;set;}
  public string ModifiedByName {get;set;}
}

Since i cannot add ILeftJoin<Data, Users> multiple times to DTO declaration, is there a way to join it second time as alias?

No you can’t express multiple self joins in AutoQuery DTOs, you may be able to add them in a Custom AutoQuery implementation although for Audit information I’d typically be storing the more identifiable unique Username instead of an Id, or if you need the Id, storing both as you don’t want to be forcing multiple table joins on all your queries just to view Audit info.

1 Like