Explicit join and map return values to an existing type

I’m not sure if this is supported or not.

I have an explicit join and I’m trying to map certain values from both tables to an existing type (SearchResult) and get a List of SearchResult as a result.

public class SearchResult
{
    public string? CustomerId { get; set; }

    public int ServerId { get; set; }

    public string? Company { get; set; }

    public string? PhoneNumber { get; set; }

    public string? Name { get; set; }

    public string? Email { get; set; }
}
var explicitJoin = Db.From<CustomerPhoneNumber>()
    .Join<CustomerProperties>(
        (number, properties) => number.CustomerId == properties.CustomerId)
    .Where<CustomerPhoneNumber>(x => x.PhoneNumber != null && x.PhoneNumber.Contains("partOfPhoneNumber"))
    .Select<CustomerPhoneNumber, CustomerProperties>((customerNumber, customerProperties) => 
        new SearchResult { CustomerId = customerNumber.CustomerId, ServerId = customerNumber.ServerId, Company = customerProperties.Description, PhoneNumber = customerNumber.PhoneNumber });
  
Db.Select(explicitJoin).PrintDump();

I’m getting the following error:
variable ‘customerNumber’ of type ‘CustomerPhoneNumber’ referenced from scope ‘’, but it is not defined.

Is this supported and how can I accomplish this?

Thanks a lot.

You need to select an anonymous type in your custom select, e.g:

=> new { customerNumber.CustomerId, customerNumber.ServerId, … }

I also tried that but was getting: Input string was not in a correct format.

Ok my bad. I was doing a .PrintDump(); and for some reason that caused the error I was getting.

The results I am getting is/are CustomerPhoneNumber…

It doesn’t look like I’m getting the values I selected from both tables…

The Logging and Introspection docs show different ways you can view the query that’s executed, e.g. with the Admin Profiling UI or logging to the console with:

OrmLiteUtils.PrintSql();