Linq and associations

having these mappings:

  [Entity]
  [Table('TBLLEBENSMITTEL')]
  [Id('FHERKUNFTCD', TIdGenerator.None)]
  [Id('FLEBENSMITTELCD', TIdGenerator.None)]
  TTBLLEBENSMITTEL = class
  private
    [Column('LEBENSMITTELCD', [TColumnProp.Required], 10)]
    FLEBENSMITTELCD: string;
   
    [Column('HerkunftCD', [], 10)]
    FHerkunftCD: Nullable<string>;

  [Entity]
  [Table('TBLNAEHRWERT')]
  [Id('FTBLLEBENSMITTEL', TIdGenerator.None)]
  TTBLNAEHRWERT = class
  private
    [Association([TAssociationProp.Lazy, TAssociationProp.Required], CascadeTypeAll - [TCascadeType.Remove])]
    [JoinColumn('HERKUNFTCD', [TColumnProp.Required], 'HERKUNFTCD')]
    [JoinColumn('LEBENSMITTELCD', [TColumnProp.Required], 'LEBENSMITTELCD')]
    FTBLLEBENSMITTEL: Proxy<TTBLLEBENSMITTEL>;

 [Entity]
  [Table('TBLREZEPT')]
  [Id('FREZEPTID', TIdGenerator.None)]
  TTBLREZEPT = class
  private
    [Column('REZEPTID', [TColumnProp.Required, TColumnProp.NoUpdate])]
    FREZEPTID: Integer;

    [Association([TAssociationProp.Lazy], CascadeTypeAll - [TCascadeType.Remove])]
    [JoinColumn('HERKUNFTCD', [], 'HERKUNFTCD')]
    [JoinColumn('LEBENSMITTELCD', [], 'LEBENSMITTELCD')]
    FHERKUNFTCD: Proxy<TTBLLEBENSMITTEL>;

I want to do something like:

    NaehrwertList := mgrManager.Find<TTBLNAEHRWERT>.
    Where(
    (Linq['NaehrwertCD']._In(['GCAL', 'GJ', 'ZE', 'ZF', 'ZK', 'ZB','KMD']))
    and  (Linq['Lebensmittel']=Rezept.HERKUNFTCD)  < ---  this is not allowed 
    ).List;

What am I missing?

    
Thank you for your ongoing support!
You can't compare objects, just scalar values. Use this:



   NaehrwertList := mgrManager.Find<TTBLNAEHRWERT>
   .CreateAlias('Lebensmittel', 'L')
   .Where(
    (Linq['NaehrwertCD']._In(['GCAL', 'GJ', 'ZE', 'ZF', 'ZK', 'ZB','KMD']))
    and  (Linq['L.HERKUNFTCD']=Rezept.HERKUNFTCD.HERKUNFTCD)  
    and  (Linq['L.LEBENSMITTELCD']=Rezept.HERKUNFTCD.LEBENSMITTELCD)  
    ).List;


Would this work, too?



NaehrwertList := mgrManager.Find<TTBLNAEHRWERT>
   .CreateAlias('TTBLNAEHRWERT', 'N')
   .Where(
    (Linq['NaehrwertCD']._In(['GCAL', 'GJ', 'ZE', 'ZF', 'ZK', 'ZB','KMD']))
    and  (Linq['N.HERKUNFTCD']=Rezept.HERKUNFTCD.HERKUNFTCD)  
    and  (Linq['N.LEBENSMITTELCD']=Rezept.HERKUNFTCD.LEBENSMITTELCD)  
    ).List;

So I avoid having a third table in the SQL?

BTW: This is what I tried already, but I stumled over code completion. While this
Rezept.HERKUNFTCD.LEBENSMITTELCD

compiles, code completion does not show it.

Tx a alot!

That wouldn't work because you need to inform the associated object.

Code completion is unfortunately not working well in Delphi in some situations, I believe the IDE gets lost with all the Aurelius classes and criteria structure and simply doesn't work. Hopefully Delphi 10.4 will fix this.