How to handle exception raised in linq

后端 未结 2 660
太阳男子
太阳男子 2021-01-20 12:49

gyus! Suppose I have such simple LINQ expression

IEnumerable res =
    from rqResult in MatchesList
    select new StopListMat         


        
2条回答
  •  执笔经年
    2021-01-20 13:15

    Use the TryParseExact method to avoid not needed exceptions.
    I don't understand why you can't use the try-catch block? You really think it is not raised? Also you should check your database for the NULL-values:

    MatchDate = Convert.IsDBNull (rqResult.Row["MatchDate"]) ?   
      DateTime.MinValue : 
      DateTime.ParseExact(rqResult.Row["MatchDate"].ToString(),
        "dd.MM.yyyy HH:m:ss", 
        fmtInfo),
    Remark = (string)rqResult.Row["Remark"] ?? String.EmptyString;
    

提交回复
热议问题