Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

casting to decimal is not supported in LINQ to entities queries

$
0
0

I have this LINQ Query to calculate the revenue sum of each employee

(from E in db.Employees
                       orderby E.EmployeeID
                       select new
                       {
                           E.EmployeeID,
                           E.FirstName,
                           E.LastName,
                           TotalSales =
                       (from O in E.Orders
                        from D in O.Order_Details
                        let LineTotal = (D.UnitPrice * D.Quantity)
                        select LineTotal).Sum()
                       }).ToList()

But, once I factor in the "discount" to become 

D.UnitPrice * D.Quantity * (1-D.Discount)

it will hit error "linq to entities does not recognize the method
system.decimal to decimal method" or "casting to decimal is not supported in LINQ to entities queries" even when I tried to do some conversion and casting.

This is the data type for these properties:

  • decimal UnitPrice
  • short Quantity
  • float Discount

Any work around for this?


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>