title: Data is Null. This method or property cannot be called on Null values. Entity Framework core
body: <p>I tried to get the list of data but I am getting null from <code>GetAllList()</code> method. In this project I am using .Net core with ORM Entity Framework core code first approach with repository pattern</p>
  <p>Entity class</p>
  <pre class="lang-cs prettyprint-override"><code>public class SIDGenerator
  {
      public int Id { get; set; }
      public string TrackId { get; set; }
      public string Track { get; set; }
      public string SId { get; set; }
      public int InstanceNumber { get; set; }
      public string Comment { get; set; }
      public bool InUse { get; set; }
      public bool IsOtherSysType { get; set; }
      public bool IsDeployed { get; set; }
      public string Exception { get; set; }
     
      public DateTime ReservationDate { get; set; }
      public DateTime LastUpdated { get; set; }
      public bool IsDeleted { get; set; }
      public bool IsManuallyDefined { get; set; }
      public int ReservatedBy { get; set; }
  }
  </code></pre>
  <p>Interface</p>
  <pre class="lang-cs prettyprint-override"><code>public interface ISidGeneratorRepository&lt;T&gt; where T :SIDGenerator
  {
      T GetById(int id);
  
      /// &lt;returns&gt;List of the entity&lt;/returns&gt;
      List&lt;T&gt; GetAllList();
  }
  </code></pre>
  <p>Implementation</p>
  <pre class="lang-cs prettyprint-override"><code>public class SidGeneratorRepository&lt;T&gt; : ISidGeneratorRepository&lt;T&gt; where T : SIDGenerator
  {
      private readonly SHIELDDbContext _dbContext;
      private readonly ILoggerManager _logger;
      private readonly IDateTime _date;
      public SidGeneratorRepository(SHIELDDbContext dbContext, ILoggerManager logger, IDateTime date)
      {
          _dbContext = dbContext;
          _logger = logger;
          _date = date;
      }
   
      public void Delete(SIDGenerator entity)
      {
          throw new NotImplementedException();
      }
  
      public void DeleteById(int id)
      {
          throw new NotImplementedException();
      }
  
      public List&lt;T&gt; GetAllList()
      {
          var result= _dbContext.Set&lt;T&gt;()//This statement causes exception data is null
                 .ToList();
          return result;
      }
  
      public T GetById(int id)
      {
          var sid = _dbContext.Set&lt;T&gt;()
                      .FirstOrDefault(i =&gt; i.Id == id);
          if (sid == null)
          {
              throw new NotFoundException(&quot;Sid could not be found with id &quot; + id.ToString(), id);
          }
  
          return sid;
      }
  }
  </code></pre>
  <p>This is my dbcontext class</p>
  <pre class="lang-cs prettyprint-override"><code>public class SHIELDDbContext : DbContext
  {
      public SHIELDDbContext(DbContextOptions&lt;SHIELDDbContext&gt; options)
          : base(options)
      {
      }
  
      public DbSet&lt;SIDGenerator&gt; SIDGenerator { get; set; }
      protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
          base.OnModelCreating(modelBuilder);
          modelBuilder.ApplyConfigurationsFromAssembly(typeof(UserRoleSeedConfig).Assembly);
      }
  }
  </code></pre>
  <p>Below is my handler class</p>
  <pre class="lang-cs prettyprint-override"><code>public Task&lt;GetAllSidViewModel&gt; Handle(GetAllSidQuery request, CancellationToken cancellationToken)
  {
      try
      {
          
          var sidList = _sidRepository.GetAllList();
          if (sidList?.Count &gt; 0)
          {
              var viewModel = new GetAllSidViewModel
              {
                  sIDlist = sidList
              };
              return Task.FromResult(viewModel);
          }
  
          return null;
      }
      catch (Exception ex)
      {
          _logger.LogError(&quot;Could not retrieve SID LIST from DB&quot; + ex);
          return null;
      }
  }
  </code></pre>
  <p>Below is the table script for the above Entity</p>
  <pre class="lang-sql prettyprint-override"><code>CREATE TABLE [dbo].[SIDGenerator](
      [Id] [int] IDENTITY(1,1) NOT NULL,
      [Track] [nvarchar](max) NULL,
      [TrackId] [nvarchar](max) NULL,
      [SId] [nvarchar](max) NULL,
      [InstanceNumber] [int] NULL,
      [Comment] [nvarchar](max) NULL,
      [InUse] [bit] NULL,
      [IsOtherSysType] [bit] NULL,
      [IsDeployed] [bit] NULL,
      [Exception] [nvarchar](max) NULL,
      [ReservationDate] [datetime2](7) NULL,
      [LastUpdated] [datetime2](7) NULL,
      [ReservatedBy] [int] NULL,
      [IsDeleted] [bit] NULL,
      [IsManuallyDefined] [bit] NULL,
      CONSTRAINT [PK_SIDGenerators] PRIMARY KEY CLUSTERED 
      (
          [Id] ASC
      ) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
  ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  GO
  </code></pre>