LINQ to SQL - some advice on Decimal types !?

Public forum to share code snippets, screen shorts, experiences, etc.
Post Reply
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

LINQ to SQL - some advice on Decimal types !?

Post by Phil Hepburn »

Hi Pearl guys,

I need your help (please) with the next part of my L2S (LINQ to SQL) development.

It would appear that the query syntax for LINQ requires me to use SQL style query syntax and does not allow me to use .NET stuff in the LINQ query itself.

I have attached a few small images to show you my problem. I have a column type of 'smallmoney' which in .NET maps to a Decimal type. If I want to compare with a double 'cash' value type then I hit my problems.

Oh! and to cap it all off the .NET type is a Nullable<Decimal> needed to map to the defined SQL table column, which can be null.

HELP !! help ?? HELP !?
XS_help_Decimal_03.jpg
XS_help_Decimal_03.jpg (25.14 KiB) Viewed 347 times
XS_help_Decimal_05.jpg
XS_help_Decimal_05.jpg (39.14 KiB) Viewed 347 times
XS_help_Decimal_04.jpg
XS_help_Decimal_04.jpg (88.78 KiB) Viewed 347 times
XS_help_Decimal_01.jpg
XS_help_Decimal_01.jpg (55.52 KiB) Viewed 347 times
XS_help_Decimal_02.jpg
XS_help_Decimal_02.jpg (107.88 KiB) Viewed 347 times
Nick, where are those SQL skills of yours ;-0)

Regards,
Phil.
User avatar
robert
Posts: 4555
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

LINQ to SQL - some advice on Decimal types !?

Post by robert »

Phil,

Change the literal value to 26.13m (m = money) and it will probably compile fine.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
Phil Hepburn
Posts: 743
Joined: Sun Sep 11, 2016 2:16 pm

LINQ to SQL - some advice on Decimal types !?

Post by Phil Hepburn »

Hi Robert,

Yes, many thanks, it now all works well, and I have learned a few useful things on the way to enlightenment ;-0) Like what can and can't be placed in the query code of the LINQ statement.

In fact I had discovered the 'M' myself, but had not applied it directly as you suggested I should. Then BINGO ! Success.

A couple of useful and informative attachments for those guys interested. Note the method is one defined in the 'DataContext' class - which is the class of object which sits between the SQL Tables and the .NET business class objects - like a 'bridge' it does the mapping, along with the Attributes on the business class.

Thanks again,
Phil.
XS_help_Decimal_13.jpg
XS_help_Decimal_13.jpg (29.47 KiB) Viewed 347 times
XS_help_Decimal_11.jpg
XS_help_Decimal_11.jpg (48.76 KiB) Viewed 347 times
XS_help_Decimal_12.jpg
XS_help_Decimal_12.jpg (62.89 KiB) Viewed 347 times
Post Reply