You can find a OrderBy in a HABTM relation here.
Add Sort to your relation definition, create a Comparer that implements IComparer and that will do the trick.
In your code, that will give somthing like this :
[HasAndBelongsToMany(Table = "SupplierRecordUrls",ColumnKey = "SupplierID", ColumnRef = "RecordUrlID", Lazy = true, Sort="MyProject.RecordUrlNameComparer, MyProject.RecordUrl")]
public virtual IList<RecordUrl> RecordUrls
{
get;
set;
}
With :
public class RecordUrlNameComparer: IComparer<RecordUrl>
{
Int32 System.Collections.Generic.IComparer<RecordUrl>.Compare( RecordUrl x, RecordUrl y )
{
return new System.Collections.Comparer( System.Globalization.CultureInfo.CurrentCulture ).Compare( x.Name, y.Name );
}
} // public class RecordUrlNameComparer: IComparer<RecordUrl>
I let you read the article :)
Edit :
Your error is now : Could not instantiate comparator class [MyProject.RecordUrl.RecordUrlComparer, MyProject.RecordUrl] for collection MyProject.Supplier.RecordUrls
What I would do :
Create the Comparer as an inner class of RecordUrls.
Change the Sort to : Sort = "MyProject.Supplier.RecordUrl$RecordUrlComparer, MyProject.Supplier.RecordUrl"
If it still doesn't work, you still get the "couldn't instantiate" error, try making the Comparer class static. I'm not sure how it is used, but if it's a static call, that may do the trick :)