LINQ to Entities does not recognize the method 'System.DateTime GetValueOrDefault()'
i am facing this error when i try to add my property in a model of type date time whose value is retrieved from global function
Ex: LastModifiedDate = Global.function name(param1,param2).GetValueOrDefault,

Naimish MakwanaRank #324 · 7.7K reputationPosted Mar 9, 2023, 10:50 PM EST
Hello Basit,
Try below solution
LastModifiedDate = Global.function name(param1,param2) ?? default(DateTime);Thanks
Naimish Makwana
Sachin SinghRank #66 · 26.2K reputationPosted Mar 9, 2023, 11:39 AM EST
use this insted
Basit Nisar97 reputationPosted Mar 9, 2023, 9:41 AM EST
Any suggestion?
Tuhin PaulRank #7 · 71.9K reputationPosted Mar 10, 2023, 3:01 PM EST
The reason this solution worked is because the null coalescing operator (??) is used to handle null values. In the code, the GetValueOrDefault() method is called on the result of the Global.function name(param1,param2) call, which is causing the error because LINQ to Entities does not recognize this method.