Ricardo,
Thank you very much for that, it looks like what I need... But
unfortunately it doesn't work.
As you said, I used it before SessionFactory is built. Still, if I remove
the required precision and scale that I entered manually into .hbm.xml file
for the field that I test, it saves the value with scale=5 to the database.
I suspect that some important bit is missing in the code above.
Thanks anyway!
Cheers,
Michael.
On Thursday, August 21, 2014 9:39:59 PM UTC+10, Ricardo Peres wrote:
>
> This does the trick:
>
> foreach (var cm in cfg.ClassMappings)
> {
> foreach (var p in cm.PropertyIterator)
> {
> if (p.Type is DecimalType)
> {
> foreach (var c in p.ColumnIterator.OfType<Column>())
> {
> c.Precision = 20;
> }
> }
> }
> }
>
>
> Make sure you call this before you build the session factory. "cfg" is the
> Configuration instance. Check with this:
>
> var cm1 = cfg.ClassMappings.Single(c => c.MappedClass ==
> typeof(Product));//any class with Decimal propertiesvar p1 =
> cm1.GetProperty("Price");//any Decimal propertyvar c1 =
> p1.ColumnIterator.OfType<Column>().Single();
> Assert.IsTrue(c1.Precision == 20);
>
>
> RP
>
> On Thursday, August 21, 2014 1:55:21 AM UTC+1, Michael Karmazin wrote:
>>
>> Ricardo, thanks for that!
>>
>> Could I ask you to show an example of how to do it? I cannot find
>> anything related in the documentation.
>>
>> Thanks,
>> Michael.
>>
>>
>> On Tuesday, August 19, 2014 9:09:32 PM UTC+10, Ricardo Peres wrote:
>>>
>>> You can mix both, that is, you can specify a convention for all
>>> properties of type decimal on top of the hbm.xml mappings.
>>>
>>> RP
>>>
>>> On Tuesday, August 19, 2014 7:01:23 AM UTC+1, Michael Karmazin wrote:
>>>>
>>>> I'm upgrading a very large project from old-old-old NH2.0.0 to NH3.3.3.
>>>>
>>>> Apart from many other problems that are mainly solved, there is a
>>>> change in decimal mapping behaviour: it seems that the default scale for
>>>> decimal values in NH3.3.3 is 5, while the old one has at least 6. So when
>>>> saving a decimal to the database, the old one saves 0.654321 as it is,
>>>> while NH3.3.3 saves it as 0.654320.
>>>>
>>>> We're using hbm.xml mapping files. Of course it's possible to specifiy
>>>> the scale and precision for every decimal property explicitly, but there
>>>> are thousands properties in our classes in total and about 500 of them are
>>>> decimal - so that could be quite a task. I'm wondering is there any
>>>> resonable way to specify default presicision and scale for us?
>>>>
>>>> I already found the posts which suggest to go the ModelMapper way (e.g.
>>>> http://stackoverflow.com/questions/15948439/nhibernate-map-all-decimals-with-the-same-precision-and-scale),
>>>>
>>>> but I cannot see how I can use it with hbm.xml files.
>>>>
>>>> Thanks,
>>>> Michael.
>>>>
>>>
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/d/optout.