How to: create Decimal metafield with custom precision

If you are using catalog system, the way of creating metafields are easy – in fact, you can forget about “metafields”, all you should be using is the typed content type. Adding this attribute to your property is enough to set the precision as you wish.

        [DecimalSettings(10, 2)]
        public virtual Decimal MyAttributesDecimal { get; set; }

Thing is a little different if you are using order system. You don’t have the strongly typed order types to work with. To automate the metafield creation, you will have to use the underlying MetaField API yourself. You probably know how to create a metafield and add it to a desirable metaclass

            var metaField = MetaField.Create(MetaDataContext.Instance, "Mediachase.Commerce.Orders.System.Shipment", "NewMetaField3", "new", "temp",
                MetaDataType.Decimal, 17, true, true, false, false);
            var metaClass = MetaClass.Load(MetaDataContext.Instance, "ShipmentEx");
            metaClass.AddField(metaField);

However, metafield created this way will be added to the metaclass with the default (18, 0) precision, which is kind of pointless. How to control the precision of the decimal metafields?

The little secret is with the MetaField.Attributes. There are two attributes that control the precision of decimal type: MdpPrecision, and MdpScale. You have to set those after the metafield is created, but before it’s added to the metaclass (the reason was simple: the underlying query to add the column to the table looks for those values to set the precision of the column). Your code should look like this

var metaField = MetaField.Create(MetaDataContext.Instance, "Mediachase.Commerce.Orders.System.Shipment", "NewMetaField5", "new", "temp",
    MetaDataType.Decimal, 17, true, true, false, false);
metaField.Attributes["MdpPrecision"] = "38";
metaField.Attributes["MdpScale"] = "9";
var metaClass = MetaClass.Load(MetaDataContext.Instance, "ShipmentEx");
metaClass.AddField(metaField);

A small but important note to remember: both of the attributes must be set, even if you want to leave one to default value.

And Tada!

Best deals on Amazon.se week 3/2025

Anker MagGo Power Bank, Qi2 Certified 15W MagSafe Compatible Portable Charger, 10.000mAh Battery Pack 

Reduced to kr799.00

https://amzn.to/3Wj6jlb

Soundcore by Anker Q20i Hybrid Active Noise Cancelling Headphones Wireless Over-Ear

Reduced to kr399.00

https://amzn.to/4fYN7QX

Regina Chamomile Paper 3-Ply Toilet Paper | 56 Roll Packs 

Reduced to kr250.63

https://amzn.to/3WnvtPP

OXO Good Grip 3-Piece Kitchen Tools & Utensil Set, Swivel Peeler, Can Opener, Whisk [Amazon Exclusive] : Amazon.se: Home & Kitchen

Reduced to kr131

Best deals on Amazon.se week 1/2025

Fjällräven Greenland Winter Jacket, size S

Normally 3999kr, reduced to kr2,363.89

https://amzn.to/4a0wwux

Samsung Galaxy Buds3 Pro

Reduced to kr1,727.08

https://amzn.to/3W6En3P

Kenwood Titanium Chef Baker Silver KVC85.004SI, Kitchen Assistant Food Processor, Integrated Scale, 3 Hook and Beaters for Mixing Stainless Steel and Rubber Beater, Bowls of 5L and 3.5L, 1200W, Silver

Reduced to kr4,058.00

https://amzn.to/3W2qBPV

Fluke Fluke 117 Multimeter, 600 V, Black, Yellow


Reduced to kr3,097.00

https://amzn.to/3ZVMC40

8Bitdo Ultimate C Bluetooth Controller for Switch with 6-axis Motion Control and Rumble Vibration (Pink)

Reduced to kr249.00, and a further 15% if buy 10 qualifying items with Prime membership

https://amzn.to/3BRKi69

Anker Prime Charger, 200W 6-Port GaN Charging Station

Reduced to kr749.00

https://amzn.to/3BMDg2B

Philips Airfryer Combi 7000 Series XXL – 8.3L (2kg), 22-in-1 airfryer (HD9876/90)

Reduced to kr2,499.00

https://amzn.to/4achn9t

Anker 335 67W Charger

Reduced to  kr299.00

https://amzn.to/3BXg3e4

Best deals on Amazon.se week 52/2024

AUDIO TECHNICA AudioT AT2035 Condenser Microphone

Reduced to  kr1,347.43

https://amzn.to/4fwYSxH

Fjällräven Women’s Expedition Parka No.1 W Jacket

Reduced to kr4,884.51

https://amzn.to/406jIzf

Philips Connected AC4236/10 Air Purifier

Reduced to kr2990

https://amzn.to/4fwFQaO

Levi’s herr Jeans 501 Original Fit

Reduced to kr699

https://amzn.to/3ZUD0q6

LG 32GS60QC-B – Ultragear monitor, 32″ QHD, 2560 x 1440, VA panel, 16:9, HDMI, 1 ms, 180Hz, FreeSync

Reduced to kr2,458.00

https://amzn.to/3ZROVoD

Fjallraven Expedition Long Down Parka W Jacket for Women

Reduced to kr4,546.31

https://amzn.to/3ZKjwUY

PC GAMING Aqua PC Gamer – NVIDIA RTX 4060 8G – Watercooling 240mm white – Aqua View XT Case – B760-WIFI – Corsair Vengeance SL 2X8GB DDR4 3600 WH – SSD 1TB PCI 4.0 – Windows 11 Pro

Reduced to kr8,635.64

https://amzn.to/4fAI5JW

Merrell Herr Moab 3 GTX vandringssko

Reduced to kr773.00

https://amzn.to/41Skx0e

PlayStation VR2

Reduced to kr4,697.07

https://amzn.to/3PdiX1b

My best purchases from Amazon, 2024 editions

Verbatim 43888 External Slimline Blu-Ray Burner

One of my last purchase in 2024 turned out to be one of the best. I wanted to rip my bluray collection for a while, for convenience, but has always been put off by selecting the right drive. I have no space for an internal drive, and not every drive can rip 4K bluray – you will need to flash firmware. Turned out there is one that just works out of the box. Pop out the drive, plug it in, and start ripping. Simple as that.

It is fairly quiet most of the time (depending on the disc), and it just works. Speed is a bit slow given size of the 4K bluray, and it is a slim, external drive, but I can’t really complain

https://amzn.to/4iH4oAn at around 1200kr (1300kr with 100kr coupon at check out at the time of writing)

OXO Good Grips Kitchen & Herb Scissors

This is my favorite kitchen scissors. Victorinox one is good also, but this feels more sturdy when holding. And boys it just cut through every thing – for example if you need to cut down a chicken. It does not shy to cut through bone. And it’s stainless steel so you can just throw it to the dish washing machine. It can be quickly dissembled and assembled in seconds. Nothing to complain about, just a terrific kitchen scissors

https://amzn.to/4fnpKjG at around 250kr

The runner is Victorinox one

https://amzn.to/4fFiNL3 at around 220kr

Nordic Ware 44671AMZ Prism Large and Half Sheet Set, Aluminum

The absolute best baking sheets by Nordic Ware, in thick aluminum, made in the USA. If you are a fan of baking cookies, they are a must. Sadly at this point of writing they are out of stock, but they were available for around 250kr for a long time. Make sure to snatch one when it’s available again, a steal at that price – one piece is more than that (250kr) in other stores, and here you get two

https://amzn.to/3ZMvcG

OXO Good Grips Y Peeler

There are many good peelers out there and my best performance on price would be from Victorinox – it can peel carrots like there is no tomorrow. and it’s that good. Sadly it is no longer available from Amazon themselves and you have to buy from 3rd party seller which means additional shipping fees.

https://amzn.to/3ZLz4bg at around kr54.30

I also have an OXO peeler which I bought a few years ago but did not use it that much, but a friend of mine visited recently and insist that I buy for her this (she is of course paying). It is a great peeler anyway and some might prefer it to the Victorinox one as the handle is more comfortable. I bought one for my friend and she is more than happy with it. Maybe you will, too.

https://amzn.to/3BNYI75 at around 125kr.

Neutrogena Concentrated unscented hand cream (50 ml)

In many positive things about Sweden, I suffer from the cold, dry winter, and my hands suffer the most. My collection of hand moisturizers could somewhat be comparable to my wife’s skincare collection. I had anything from O’Keefee’s to Cerave to Eucerin, they helped a little but nothing really solved my problem. Enter Neutrogena hand cream. Really a life saver. Wish I knew it 9 years ago.

https://amzn.to/4glZh7e at around 38kr

Best deals on Amazon.se week 51/2024

Fjallraven 87177-244 Vidda PRO Pants M Sports Pants Men’s Suede Brown Size 48/L

Easily 2000kr on other shops

https://amzn.to/3ZZemVB

Dreame L40 Ultra Robot Vacuum Cleaner with Removable and Liftable Mop, Extendable and Liftable Side Brush, 11000Pa Suction Power, 65°C Mop and Washboard Self-Cleaning, Automatic Draining, Automatic

Reduced to kr9,770.29

https://amzn.to/41w0sMW

Yes Max Power Dishwasher Liquid Pomegranate 650ml, Easy and smooth cleaning, even for your dirtiest pots and pots

Reduced to kr35.49

https://amzn.to/3VKNzL5

Dreame Z10 Station with auto empty station

Reduced to kr2,999.00

https://amzn.to/3DfWhdU

Philips SONICARE W2 Optimal White Standard Sonic Toothbrush Heads in Original Design – Pack of 8 Units in White 

Reduced to kr349.00

https://amzn.to/3VEUPrW

ECCO Men’s Track 25 Mid GtxClassic Boots

Reduced to kr1,287.17

https://amzn.to/41F35w4

Waterpik Ultra Professional Water Flosser, Mouth Shower With 7 Nozzles And Advanced Control Of Water Pressure With 10 Settings, Tool For Removing Plaque, White (WP-660EU)

reduced to kr599 (reduced 100kr at check out)

https://amzn.to/3ZZ9wJ3

Apple iPad Pro 11 tum (M4): Ultra Retina XDR-skärm, 512 GB, skärmkamera på långsidan med 12 MP/kamera på baksidan med 12 MP, wifi 6E + 5G, batteri som räcker hela dagen, Standardglas – silver

Reduced to kr14,882.81

https://amzn.to/3BEDaKg

Best deals on Amazon.se week 50/2024

Philips Sonicare Original W2 Optimal White HX6066/10

Reduced to kr289.99

https://amzn.to/3BlL4Io

Several UGREEN USB C Hub reduced to Black Friday prices

https://amzn.to/4g3ZUCo

Thermos Bottle + Tea/FRUIT Filter Infuser, Insulated Stainless Steel Water Bottle, BPA Free | Drink Bottle + Tea Infuser / Fruit Insert, 450ml To-Go Thermo Cup Thermo Flask: Office Sports School

Reduced to kr227.99

https://amzn.to/4iv5Oy7

Philips Hx9611/19 Sonicare Expertclean 7300 Elektrisk Tandborste, Vit, Paket med 2

Reduced to kr1,577.13

https://amzn.to/3D9AHI7

Noctua NF-A12x25 PWM chromax.black.swap, Silent Premium Fan, 4-Pin (120mm, Black)

Reduced to kr199

https://amzn.to/49M9HuF

Merrell Moab 3 GTX men trekking shoes

Reduced to kr850

https://amzn.to/4f7GdZb

LEGO Technic Koenigsegg Jesko Absolut Grey Hyper Car, Construction Set for Boys and Girls, Toy Car for Kids, Buildable Model Set, Gift Idea for Motor Enthusiasts 42173

Reduced to kr390

https://amzn.to/4g9UlCi

Produkt: Apple MacBook Air 15.3″ (2024) – M3 OC 10C GPU 16GB RAM 512GB SSD

Reduced to kr15,743.52

https://amzn.to/4iyzom7

Yes Platinum All In One Dishwasher Detergent, 94 Dishwasher Tablets

Reduced to kr138.89

https://amzn.to/4fiK7hM

TIMEMORE Coffee Scale Basic 2.0 Espresso Scale

Reduced to kr542.40

https://amzn.to/3PcEqaN

Technics EAH-AZ80E-K Wireless Headphones with Noise Cancellation, Multipoint Bluetooth 3 Devices, Comfortable In-Ear Headphones, Wireless Charging, Black

Reduced to kr2,413.60

https://amzn.to/3ZwlCI4

Eneloop Pro BK-3HCDE/4BE Batteries AA

Reduced to kr80

https://amzn.to/4iAKlUk

ESI U22 XT | Professional 24-bit USB Sound Card
Reduced to kr516.78. Can be combined with the Spend 600kr get 100kr discount

https://amzn.to/4gsi0Ou

BGS 32100 | U-Ring Wrench Set | Inch Sizes | 3/8″ – 11/16″ | 6 Pieces

Reduced to kr89.34

https://amzn.to/4gnjZDK

Swiffer mop wipes (12 pads)
Reduced to kr35.79

https://amzn.to/4iL6kbf

LEGO Technic NEOM McLaren Formula E Racing Car 42169

Reduced to kr413.99

https://amzn.to/41Lr9Nx

Gillette Fusion 5 Razor Blade Refills for Men, 8pcs

Reduced to kr250.39

https://amzn.to/41Nk4MO

AsyncHelper can be considered harmful

.NET developers have been in the transition to move from synchronous APIs to asynchronous API. That was boosted a lot by await/async keyword of C# 5.0, but we are now in a dangerous middle ground: there are as many synchronous APIs as there are async ones. The mix of them requires the ability to call async APIs from a synchronous context, and vice versa. Calling synchronous APIs from an async context is simple – you can fire up a task and let it does the work. Calling async APIs from a sync context is much more complicated. And that is where AsyncHelper comes to the play.

AsyncHelper is a common thing used to run async code in a synchronous context. It is simple helper class with two methods to run async APIs

        public static TResult RunSync<TResult>(Func<Task<TResult>> func)
        {
            var cultureUi = CultureInfo.CurrentUICulture;
            var culture = CultureInfo.CurrentCulture;
            return _myTaskFactory.StartNew(() =>
            {
                Thread.CurrentThread.CurrentCulture = culture;
                Thread.CurrentThread.CurrentUICulture = cultureUi;
                return func();
            }).Unwrap().GetAwaiter().GetResult();
        }

        public static void RunSync(Func<Task> func)
        {
            var cultureUi = CultureInfo.CurrentUICulture;
            var culture = CultureInfo.CurrentCulture;
            _myTaskFactory.StartNew(() =>
            {
                Thread.CurrentThread.CurrentCulture = culture;
                Thread.CurrentThread.CurrentUICulture = cultureUi;
                return func();
            }).Unwrap().GetAwaiter().GetResult();
        }

There are slight variants of it, with and without setting the CurrentCulture and CurrentUICulture, but the main part is still spawning a new Task to run the async task, then blocks and gets the result using Unwrap().GetAwaiter().GetResult();

One of the reason it was so popular was people think it was written by Microsoft so it must be safe to use, but it is actually not true: the class is introduced as an internal class by AspNetIdentity AspNetIdentity/src/Microsoft.AspNet.Identity.Core/AsyncHelper.cs at main · aspnet/AspNetIdentity (github.com) .That means Microsoft teams can use it when they think it’s the right choice to do, it’s not the default recommendation to run async tasks in a synchronous context.

Unfortunately I’ve seen a fair share of threads stuck in AsyncHelper.RunSync stacktrace, likely have fallen victims of a deadlock situation.

    756A477F9790	    75ABD117CF16	[HelperMethodFrame_1OBJ] (System.Threading.Monitor.ObjWait)
    756A477F98C0	    75AB62F11BF9	System.Threading.ManualResetEventSlim.Wait(Int32, System.Threading.CancellationToken)
    756A477F9970	    75AB671E0529	System.Threading.Tasks.Task.SpinThenBlockingWait(Int32, System.Threading.CancellationToken)
    756A477F99D0	    75AB671E0060	System.Threading.Tasks.Task.InternalWaitCore(Int32, System.Threading.CancellationToken)
    756A477F9A40	    75AB676068B8	System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task, System.Threading.Tasks.ConfigureAwaitOptions)
    756A477F9A60	    75AB661E4FE7	System.Runtime.CompilerServices.TaskAwaiter`1[[System.__Canon, System.Private.CoreLib]].GetResult()

An further explanation of why this is bad can be read here

c# – Is Task.Result the same as .GetAwaiter.GetResult()? – Stack Overflow

Async/sync is a complex topic and even experienced developers make mistake. There is no simple way to just run async code in a sync context. AsyncHelper is absolutely not. It is simple, convenient way, but does not guarantee to be correct thing in your use case. I see it as a shortcut to solve some problems but create bigger ones down the path.

Just because you can. doesn’t mean you should. That applies to AsyncHelper perfectly