bubibubi / JetEntityFrameworkProvider

Microsoft Access (Jet) Entity Framework provider
88 stars 26 forks source link

Cast issue for type Decimal #27

Open hubert17 opened 6 years ago

hubert17 commented 6 years ago

I am raising this issue. I encountered this issue when using type Decimal. Non-issue for type Double.

storeDb.Carts.Where(x => x.CartId == ShoppingCartId).Sum(t => t.Quantity * t.Item.UnitPrice);

InvalidOperationException: invalid PrimitiveTypeKind for cast(): cannot handle type Decimal with Jet

bubibubi commented 6 years ago

Could you please provide the model? I can't reproduce the issue (see Model74_Decimal_Jet)

hubert17 commented 6 years ago

Hi Bubi! I have fixed the issue by .ToList() first before .Sum()

Check this out. https://github.com/hubert17/MyAspNetMvcApp/blob/e0fbf271cab37c6d5f70ddfde299b608c677d16e/MyAspNetMvcApp/Areas/OrderFramework/ViewModels/ShoppingCart.cs#L137

bubibubi commented 6 years ago

I'll check it out.

About ToList consider that you materialize the list of records and then you compute the sum (instead of materializing the sum) so it's bad for large amount of data.

hubert17 commented 6 years ago

Eggzacklee. I'm looking forward for the best fix of this issue. Thanks!