I am doing a repository call in EF, as soon as i access First or default i am getting null reference exception, could any body help with inputs?
is there any way to check if the Entity values are null? so that i can avoid Exception.
public TEntity GetSingle(Func<TEntity, bool> where, params Expression<Func<TEntity, object>>[] navigationProperties) { TEntity item = null; using (var context = new CDREntities()) { IQueryable<TEntity> dbQuery = context.Set<TEntity>();
below line returns 56 entities with null values, because i dont have any entities in the table
//Apply eager loading dbQuery = navigationProperties.Aggregate(dbQuery, (current, navigationProperty) => current.Include(navigationProperty));
below is the place where i get null reference exception when i access above null entities, is there any thing wrong with the below statement?
item = dbQuery .AsNoTracking() //Don't track any changes for the selected item .FirstOrDefault(where); //Apply where clause } return item; }