'ASP.NET Core - Possible Null Reference Return in Generic Repository

In ASP.NET Core-6 Entity Framework, I am using Generic Repository:

public interface IGenericRepository<T> where T : class
{
    Task<T> GetByIdAsync(object id);
}

public class GenericRepository<T> : IGenericRepository<T> where T : class
{
    private readonly ApplicationDbContext _context;
    internal readonly DbSet<T> _table;

    public GenericRepository(ApplicationDbContext context)
    {
        _context = context;
        _table = context.Set<T>();
    }

    public virtual async Task<T> GetByIdAsync(object id)
    {
        return await _table.FindAsync(id);
    }
}

I got this warning:

'_table' is not null here Possible Null Reference Return in Generic Repository

How do I resolve this?

Thank you



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source