I have the following code:
public IEnumerable<Report> GetReport(int reportId)
{
var dbReport = dbContext.ReportsTbl.Where(w =>w.ID == reportId);
return dbReport;
}
What I like to do though us to get First
If I do:
public IEnumerable<Report> GetReport(int reportId)
{
var dbReport = dbContext.ReportsTbl.First(w =>w.ID == reportId);
return dbReport;
}
How do I get it to do First(). It is complaining about it being IEnumerable.
You need to change the method signature to return only a single object instead of a collection:
public Report GetReport(int reportId)
{
var dbReport = dbContext.ReportsTbl.First(w =>w.ID == reportId);
return dbReport;
}
If for some reason you do actually want a collection containing only the first element you could use .Take(1) instead of First.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With