Link to home
Start Free TrialLog in
Avatar of Peter Groves
Peter GrovesFlag for Canada

asked on

The required column was not present in the results of a 'FromSql' operation.

I get this error retrieving data from server. Yet if I execute the stored procedure from server explorer it shows all the data fine.  
namespace OASIS_MVC.Models
    public partial class AnalSubTask
        public int subTaskID { get; set; }
        public string Ident { get; set; }
        public DateTime? DateCreated { get; set; }

Open in new window

       public async Task<IActionResult> Index()
            var getanalsub = (IEnumerable<AnalSubTask>)_context.AnalSubTasks.FromSqlRaw("spGetanalsub null").ToList();
                return View(getanalsub);

Open in new window

namespace OASIS_MVC.Data
    public class ApplicationDbContext : DbContext
        public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)

        public DbSet<AnalSubTask> AnalSubTasks { get; set; }

Open in new window

SELECT Anal_sub_task.ident,
       Anal_sub_task.sub_TaskID ,
  FROM DATAHUB.dbo.Anal_sub_task
       where  Anal_sub_task.reseau = ISNULL(@res,Anal_sub_task.reseau) 

Open in new window

This is from the serer explorer stored procedure execution that shows sub_TaskID is there.
User generated imageI tried add [Primary Key] to sub_TaskID  in the stored procedure , as it is the primary key for the table.

Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Peter Groves


I can't believe I lost that much time on this because I missed seeing the underscore. I check the spelling 4-5 times and
missed it every time. There was even errors where I changed the t in sub_TaskID   to the T. No fun getting old LOL .
I missed the underscore in most of the fields. What I don't get is I created the model was created via scaffolding and I was sure it wouldn't make any errors.