如何在 LINQ Query C# 中设置 Null-able Guid 值

How to set Null-able Guid value in LINQ Query C#

我有 Guid,我通过

将其标记为可为空
public struct abc
{
    public Guid Id { get; set; }
    public Guid? PreviousCalculatedId { get; set; }
    public Guid? NextCalculatedId { get; set; }
}

但是我在 LINQ 查询 PreviousCalculatedId 和 NextCalculatedId 时遇到构建错误

错误

   error is cannot implicitly convert type system.Guid to bool

.

 var answerDataView = (from Calc in dbContext.Calculation
                       where Calc .abcId == abcId && Calc .Id == GivenCalcId
                        select new abc
                          {
                            Id = mylist.listedItemId,
                            Text = Calc .Value,
                            NextCalculatedId? = sortedAnswerList.ItemOnRight[0],
                            PreviousCalculatedId? = sortedAnswerList.ItemOnLeft.ElementAt(0),


                               });

试试这个,

var answerDataView = (from Calc in dbContext.Calculation
                      where Calc .abcId == abcId && Calc .Id == GivenCalcId
                      select new abc
                      {
                            Id = mylist.listedItemId,
                            Text = Calc .Value,
                            NextCalculatedId = sortedAnswerList.ItemOnRight[0] ?? null,
                            PreviousCalculatedId = sortedAnswerList.ItemOnLeft.ElementAt(0) ?? null,
                       });