0

I have problem when I call GetById(id), it's return null instead of book. it should be return book that have the same id. there is no error but when I debug it show NullReference Exception" object reference not set to an instance of an object".

if any one can help me I will appreciate it. here is the code

 public async void Save (Page p){

 Book book = await GetById(p.id);
 }

the error is on retrieving data from db, the GetById will retrieve object of type book but the problem here it is retrieve null.

public async Task<TEntity> GetById(long id){
return await _dbSet.FindAsync(id);
}
Sahar
  • 19
  • 2
  • Have you checked whether `Page p` param is null or not? – Izzy Aug 12 '21 at 13:56
  • @arne awaiting the task returns the result, or throw an appropriate exception if the task was canceled or faulted. – JonasH Aug 12 '21 at 14:05
  • Can you post the `FindAsync` function? – Henrique Pombo Aug 12 '21 at 14:10
  • @arne You should remove your comments if they're incorrect. That way it's less likely to confuse others. You can do that by hovering your mouse cover over the comment, and then a Delete hyperlink will appear. – mason Aug 12 '21 at 17:09

0 Answers0