public class Version
{
public byte Major { get; set; }
public byte Minor { get; set; }
public short Build { get; set; }
public int Revision { get; set; }
private long NumVersion
{
//get {}
//set {}
//Some logic that make Int64 number that represents this verion
}
}
Suppose I want to be able to write queries like
Where<Product>(t=>t.Version > new Version(1,2,0,0))
In Product table I store only Int64 NumVersion field, so Version property is mapped as component, and currently I query it like Where<Product>(t=>t.Version.NumVersion > new Version(1,2,0,0).NumVersion)
In C# I can 1. Overload comparison operators, 2. Make it implicitly casted to long like:
public static implicit operator long(Version v)
{
return v.NumVersion;
}
This will allow me to compare Version objects, but how to make NHibernate understand this and generate proper SQL ?
It is impossible. You will either have to explicitly write comparisons for each
Versioncomponent or filter on the client side.