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

时间:2018-02-16 07:29:41

标签: linq guid .net-core-2.0

我有Guid,我用

标记无效
public struct abc
{
    public Guid Id { get; set; }
    public Guid? PreviousCalculatedId { get; set; }
    public Guid? NextCalculatedId { get; set; }
}

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

错误

   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),


                               });

1 个答案:

答案 0 :(得分:2)

试试这个,

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,
                       });

并且