Dylan v.d Merwe - 203 - Nov 22, 2014

Hi Demis

I have a situation where I am trying to Join tables and there are duplicate fields. 

I have a POCO called FullVenue which will contain a combination of fields from the Venue and Region tables. Venue has fields like Name, Address, RegionId, ContactNumber, NumberOfTables, Latitude, Longitude, etc. Region has fields like Name, Area, Country, Latitude, Longitude, etc.

As you can see there are some overlapping fields (Name, Latitude, Longitude). In the FullVenue POCO I thought there may be an attribute that maps a field regardless of it’s name to a Type and Field. 

For example:
public class FullVenue {
   [Alias(typeof(Venue), “Latitude”)]
   public double Latitude {get;set;}

   [Alias(typeof(Region), “Latitude”)]
   public double Region_Latitude {get;set;}
}

Is there some way of combining duplicate fields like the above in OrmLite joins? Without some kind of attributed mapping above the SQL the join would generate would ignore the Region_Latitude field (obviously) as it does not map to Region or Venue fields. 

var results = db.Select<FullVenue>(db.From<Venue>().Join<Venue, Region>((x, y) => x.RegionId== y.Id);

The only way to specify multiple columns with the same name across multiple joined tables is by naming convention, see:
https://github.com/ServiceStack/ServiceStack.OrmLite#selecting-multiple-columns-across-joined-tables

So your joined model would look like:

public class FullVenue {
   public double VenueLatitude {get;set;}
   public double RegionLatitude {get;set;}
}

Dylan v.d Merwe:

Well that makes my scenario even easier! Must’ve missed that. The attribute may allow more customization in the future :slight_smile: