I am new to EF Core Framework and trying to learn it. I have tried executing a SQL Query and got the response from the DB but now trying to convert the below SQL query in to Linq query to use it with the EF Core. My SQL Query is like below
public static string shipQuery = @"SELECT distinct newid() as Id
,[prj_number]
,[ship_Date]
,[delivery]
,,CONVERT(VARCHAR(10), [delDate], 110) as delDate
,[po]
,[so]
,SUM([qty_so]) as total_qty
FROM [sDev].[dbo].[PrjDetails]
where [Rep_Prj] = @rep and [so_status] not in ('Canceled','Voided lines')
group by Id,[prj_number],[ship_Date],[delivery],delDate,[po],[so]
ORDER BY ship_Date DESC";
I have used this SQL Query in to my EF Core Framework to get the data like
_context.shipByRepo.FromSql<shipByRepo>(shipQueries.shipQuery, rep).ToList();
This works as expected. To improvise the framework I am trying to convert the query in to Linq query.
As intial try I just filtered by the rep
_context.shipByRepo.Where(w => w.Reporting_Project == rep).ToList();
And this works, but I am not sure how can I do the above like like doing the date conversion& sum along with the Group by and Orderby
Earlier with the SQL Query I had the model as
public class shipByRepo : IshipByRepo
{
public Guid Id { get; set; }
public string prj_number { get; set; }
public string ship_Date { get; set; }
public string delivery { get; set; }
public string delDate { get; set; }
public string po { get; set; }
public string so { get; set; }
public decimal? total_qty { get; set; }
}
But with the Linq query I changed I modified the Model class without including the total quantity/Converted date fiels
public class shipByRepo : IshipByRepo
{
public string prj_number { get; set; }
public string ship_Date { get; set; }
public string delivery { get; set; }
public DateTime? delDate { get; set; }
public string po { get; set; }
public string so { get; set; }
}