I would like to use "Equals" to check wether a value in my DB and another given value are the same.
Unfortunatly, NHbernate does not seam to support "Equals", so I searched in the internet and found this tutorial: http://www.primordialcode.com/blog/post/nhibernate-3-extending-linq-provider-fix-notsupportedexception
At the end, I have to register the extension - but in which file should I do that?
Edit
Maybe I should describe my problem a bit better...
The situation: I have a enumeration called "GoodsType". Possible values are for example "Iron", "Wood", "Stone", etc. This enum is used in the class "InventoryGoods":
public class InventoryGoods: Goods
{
public virtual User Owner { get; set; }
public virtual Guid Id { get; set; }
public virtual long Amount { get; set; }
public virtual GoodsType GoodsType { get; set; }
public virtual float Price { get; set; }
}
If a user want to sell something, I have to check wether he has enough of this specific good. I created a function for this check. This function is able to find the actual Owner by itself (the user which is logged in), so I only have to send the GoodsType and the Amount.
But if I use this request: InventoryGoods good = _repository.First(x => (Equals(x.GoodsType, GivenGoodsType)) && (x.Amount >= GivenAmount));, the script stops with the error System.NotSupportedException: Boolean Equals(System.Object, System.Object)
I searched a lot, and somewhere on SO (unfortunatly I don't remember the link) I found the statement that "Equals" is not supported by NHibernate (because it is not translateable to SQL). So I searched for a solution and found the tutorial named above. But I'm unable to find the file where I have to register the extension.
I already found this solution: InventoryGoods good = _repository.First(x => x.Amount >= GivenAmount).Where(x => (Equals(x.GoodsType, GivenGoodsType)));, but I would prefer a way without double-checking via "Where", only with "First".
Edit 2
I'm using Fluent NHibernate for my mapping.