I am not sure the problem relates to LLBLGen anymore (so don't have to spend time on it), but here is the story:
The origin of the problem is mapping between two data structures. One is from an existing (and old) database and the other is a new database.
In the old datamodel a Car (if we continue with this metaphor) is saved in a somewhat flat structure. This means that, for example, the Material and the Car Designer is saved as a string.
In the new model, the material is a simple basedata class (Id and MaterialName) with a 1-Many relationship to the Car. The Car Designer is a more complex class consisting of both basedata classes (for example City and Country) and "normal" classes as Address. The Car Designer has a Many-To-Many relationship with Car.
When I map the data from the old to the new, I need to check the database for existing Cars, Car Designers and all associated basedata (Material, City and Country).
The basedata is simple (something like: if basedata.Name == "new basedata" then either create a new one or return the existing one), however Cars and Car Designer is more complex.
The Linq queries to test for a, for example, Car Designer got to complex and had to take into account that some basedata does not exist. The code below is taken from a real method:
public static LocationEntity AddOrGetLocationEntity(string address, string zipCode, string city, double? latitude, double? longitude, double? heading, string country, int? radius, string description, string collection)
{
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
var data = new LinqMetaData(adapter);
var locationEntity = data.Location.SingleOrDefault(x => string.Equals(x.Address.Trim(), address.Trim(), StringComparison.OrdinalIgnoreCase)
&& string.Equals(x.City.Name.Trim(), city.Trim(), StringComparison.OrdinalIgnoreCase)
&& string.Equals(x.ZipCode.Trim(), zipCode.Trim(), StringComparison.OrdinalIgnoreCase)
&& x.Latitude == latitude
&& x.Longitude == longitude
&& string.Equals(x.Country.Name.Trim(), country.Trim(), StringComparison.OrdinalIgnoreCase)
&& x.Radius == radius
&& x.Heading == heading
&& string.Equals(x.Description.Trim(), description.Trim(), StringComparison.OrdinalIgnoreCase)
&& string.Equals(x.Collection.Name.Trim(), collection.Trim(), StringComparison.OrdinalIgnoreCase)
);
...
}
}
This obviously fails if the some of the basedata is null and adding checks for that seemed to make the whole thing even more complex. This is when I thought about creating a Hash of the data and comparing that instead and hence the original question