var _NotifyData = (from Notification in _dbContext.Notification
join MstStage in _dbContext.MstStage on Notification.Status equals MstStage.Id
where Notification.DeptId == (DeptId == 0 ? Notification.DeptId : DeptId) && Notification.Status == (Items.Status == 100 ? Notification.Status : Items.Status)
&& Notification.CreatedOn >= (Items.FromDate == string.Empty ? Notification.CreatedOn : ApplicationData.AppStringToDatetime(Items.FromDate)) && Notification.CreatedOn <= (Items.ToDate == string.Empty ? Notification.CreatedOn : ApplicationData.AppStringToDatetime(Items.ToDate))
orderby Notification.CreatedOn descending
select new NotifyData
{
RefNId = Notification.RefNid,
NType = Notification.Ntype,
NotificationH = Notification.NotificationH,
NotificationB = Notification.NotificationB,
Comment = Notification.Comment,
StatusId = (int)MstStage.Id,
Status = MstStage.Mode,
CreatedBy = (int)Notification.CreatedBy,
CreatedOn = ApplicationData.AppDateToString(Notification.CreatedOn),
ModifiedBy = (int)Notification.ModifiedBy,
ModifiedOn = ApplicationData.AppDateToString(Notification.ModifiedOn)
}).Distinct().AsEnumerable().Select((k, index) => new NotifyData()
{
SrlNo = index + 1,
RefNId = k.RefNId,
NType = k.NType,
NotificationH = k.NotificationH,
NotificationB = k.NotificationB,
Comment = k.Comment,
ApproveBy = k.ApproveBy,
StatusId = k.StatusId,
Status = k.Status,
CreatedBy = k.CreatedBy,
CreatedOn = k.CreatedOn,
ModifiedBy = k.ModifiedBy,
ModifiedOn = k.ModifiedOn,
Can_Approve = GetRegistationResult(_authenticationManager.GetAuthenticatedUser().Result.UserId, UserManageAccess.NotificationPage, UserManageAccess.NotificationApproveAction).Result,
}).ToList();Loading
Tuhin PaulPosted Mar 26, 2023, 9:35 AM
If the CreatedOn field contains null values, they will be treated as the smallest value and will be sorted first, regardless of the order by clause. You can add a where Notification.CreatedOn is not null condition to exclude null values from the result set. Also if you have implemented a custom sorting logic using a SQL trigger or stored procedure, it may override the order by clause and return the results in a different order.
Tuhin PaulPosted Mar 26, 2023, 9:34 AM
The CreatedOn field in the Notification table has the correct data type (i.e., datetime, datetime2, or datetimeoffset). If the data type is different, it may not sort the results as expected.
Sandeep KumarPosted Mar 24, 2023, 10:25 AM
This is My Table Class .model of tables
Naimish MakwanaPosted Mar 24, 2023, 10:17 AM
In the SQL query, the
CreatedOnfield is implicitly converted to adatetimedata type, whereas in the LINQ query, theCreatedOnfield is being converted to a string using theAppDateToStringmethod. If theCreatedOnfield in theNotificationentity is not already adatetimedata type, it's possible that the conversion to a string is affecting the ordering of the results.Thanks