.Net(C#)中ISNULL()的等效方法是什么?

Dot*_*mer 2 c# sql ado.net entity-framework

我有一个存储过程用于我的购物车系统,它返回总金额,看起来像这样;

ALTER PROCEDURE [dbo].[ShoppingCartGetTotalAmount]
(@CartID char(36))
AS
SELECT ISNULL(SUM(Product.Price * ShoppingCart.Quantity), 0)
FROM ShoppingCart INNER JOIN Product
ON ShoppingCart.ProductID = Product.ProductID
WHERE ShoppingCart.CartID = @CartID
Run Code Online (Sandbox Code Playgroud)

但是,现在我想在Entity Framework中做同样的事情.因此,我需要知道以下任一选项;
1)如何在Entity FrameWork中执行上述任务,即

SELECT ISNULL(SUM(Product.Price * ShoppingCart.Quantity), 0)
    FROM ShoppingCart INNER JOIN Product
    ON ShoppingCart.ProductID = Product.ProductID
    WHERE ShoppingCart.CartID = @CartID
Run Code Online (Sandbox Code Playgroud)

2)或者C#中SQL ISNULL()函数的等效是什么?
3)或者我怎样才能实现这一点 - > ISNULL(SUM(Product.Price * ShoppingCart.Quantity), 0) 使用任何.Net方法?

Ode*_*ded 7

C#具有null coalesce运算符 - ??.

?? ?? operator被称为null-coalescing运算符,用于为可空值类型或引用类型定义默认值.如果操作数不为null,则返回左侧操作数; 否则返回正确的操作数.

EF了解此运算符并正确翻译.