Estyn Edwards - 195 - Dec 18, 2014

I’m having a problem with the AutoQuery functionality. I’m trying to do multiple joins, pretty much exactly like this example: http://stackoverflow.com/questions/26783587/servicestack-autoquery-multiple-ijoin

In my case I’m doing the following:

 public class QueryMerchandise : QueryBase<Merchandise, QueryMerchandiseDTO>, IJoin<Merchandise, Donor>, IJoin<Merchandise, Bidder> { }

    public class QueryMerchandiseDTO:Merchandise
    {
        
        public string DonorName { get; set; }
       
        public string BidderName { get; set; }
       
    }

In this case DonorName get’s populated correctly, but not BidderName.  If I reverse the order of the IJoin:

public class QueryMerchandise : QueryBase<Merchandise, QueryMerchandiseDTO>, IJoin<Merchandise, Bidder>,IJoin<Merchandise, Donor> { }

Now BidderName will get populated, but not DonorName.  I’ve tried with v4.0.33.0 and v4.0.35.0.  I’ve also tried with ILeftJoin, but I get the same results.

Am I misunderstanding how the autoquery joins are supposed to work? I can easily work around this problem with a simple service, but I’m curious if autoquery can do it.

Thanks,
Estyn

Results should map to the first property in the list of joined tables. 

Are there implicit joins between each of the tables?

Which types are DonorName and BidderName on? and are you using any aliases?

Are they the property names on Donor and Bidder or just the Name properties on them, e.g:
Donor.Name
Bidder.Name?

Also do you get a populated result set when trying to use OrmLite directly, i.e:

var rows = db.Select<QueryMerchandiseDTO>(
db.From<Merchandise>()
    .Join<Donor>()
    .Join<Bidder>());

rows.PrintDump();

Estyn Edwards:

Thanks for replying. Here’ are the classes that I’m using, I’m not using any aliases:

 public class Merchandise
    {
        [AutoIncrement]
        public int Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        [References(typeof(Donor))]
        public int? DonorId { get; set; }
        [References(typeof(Bidder))]
        public int? BidderId { get; set; }
   
    }

 public class Donor
    {
        [AutoIncrement]
        public int Id { get; set; }
        public string Name{ get; set; }
        public string Address { get; set; }
    }

  public class Bidder
    {
        [AutoIncrement]
        public int Id { get; set; }
        public int BidderNumber { get; set; }
        public string Name{ get; set; }
    }

My workaround was to use a query that looks very much like yours:
Db.Select<MerchandiseResponseDTO>(
                    Db.From<Merchandise>()
                        .LeftJoin<Bidder>()
                        .LeftJoin<Donor>()

public class MerchandiseResponseDTO : Merchandise
    {
        public string DonorName { get; set; }
        public string BidderName{ get; set; }        
    }

The workaround works fine.  I tried your query and it works as well.

ok cool, and were you saying that AutoQuery still wasn’t working when you were using ILeftJoin<Merchandise,Bidder,Donor> ?

Estyn Edwards:

If I do ILeftJoin<Merchandise,Bidder,Donor> I get the following error:

“Could not infer relationship between Donor and Bidder”

Yep that’s expected if there was no relationship between them, so you’ll need to declare each join individually, i.e:

QueryBase<Merchandise,QueryMerchandiseDTO>,
ILeftJoin<Merchandise, Donor>, ILeftJoin<Merchandise, Bidder> { }

did you say this wasn’t working?

Estyn Edwards:

Yes that is what i can’t get working.

QueryBase<Merchandise,QueryMerchandiseDTO>,
ILeftJoin<Merchandise, Donor>, ILeftJoin<Merchandise, Bidder> { }

populates DonorName but not BidderName

Switching the order:
QueryBase<Merchandise,QueryMerchandiseDTO>,
 ILeftJoin<Merchandise, Bidder> ILeftJoin<Merchandise, Donor> {}

does the opposite BidderName is populated, but DonorName isn’t.

ok that’s weird if it’s working in OrmLite but not AutoQuery (which is using OrmLite underneath).

One difference in your AutoQuery vs OrmLite is that you’re using QueryMerchandiseDTO in AutoQuery but MerchandiseResponseDTO in OrmLite, does it not work when you use MerchandiseResponseDTO in AutoQuery?

If not I’ll see if I can repro tomorrow after I wake up, going to catch up on some zzz’s now.

Estyn Edwards:

Switching the DTOs didn’t make any difference it still seems to have the same behavior.   I have an effective workaround so this isn’t a high priority.  I’ll do some more testing and see if i can put together a failing test case.

Estyn Edwards:

I copied the files into a new project and it looks like it works there so it must be something related to my project, I’ll see if I can hunt it down, thanks for your help.

ok great, glad it’s sorted