NHibernate DecimalMin Validator
I'm attempting to use the DecimalMin validator from NHibernates Validator library. Unfortunately, due to compiler restrictions I'm ge开发者_高级运维tting errors when attempting to utilize it. I'm sure its something simple, but I'm at a point where I need to move onto another task and not burn anymore time on it so any help would be appreciated.
[DecimalMin(10.01)]
public decimal Amount { get; set; }
The code above uses the DecimalMin attribute with the constructor value of 10.01. The constructor of the Attribute accepts decimal values. However, the compiler will not allow 10.01 or 10.01m.
With 10.01 as the value I receive: "Cannot convert source type 'double' to target type 'decimal'
With 10.01m as the value I receive: "An attribute argument must be a constant expression, type of expression or array creation expression of an attribute parameter type."
I've googled around to try and find an answer and my google-fu is failing me today.
Does anyone have an example of how to use this validator?
This is a bug in NHibernate.Validator. Decimals are not representable in attribute parameters.
use decimal values as attribute params in c#?
The solution is to patch NHibernate.Validator so that the constructor takes a float or double and then perform the conversion to decimal in the ctor. Wish I had a better answer for you.
精彩评论