troubleshooting Question

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

Avatar of Peter Groves
Peter GrovesFlag for Canada asked on
ASP.NETMicrosoft SQL Server* stored prcedure
2 Comments1 Solution12 ViewsLast Modified:
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
    {
        [Key]
        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.date_created,
       Anal_sub_task.prime_ID,
       Anal_sub_task.sub_task_name,
       Anal_sub_task.[description],
       Anal_sub_task.[group],
       Anal_sub_task.date_vise,
       Anal_sub_task.reminder,
       Anal_sub_task.Responsable,
       Anal_sub_task.date_completsub,
       Anal_sub_task.completed_bit,
       Anal_sub_task.task_type,
       Anal_sub_task.cout_est,
       Anal_sub_task.cout_reel,
       Anal_sub_task.nomfirme,
       Anal_sub_task.status_code,
       Anal_sub_task.mandat_accepter,
       Anal_sub_task.purchase_order,
       Anal_sub_task.courriel_sent,
       Anal_sub_task.sub_TaskID ,
       Anal_sub_task.Temp_status,
       Anal_sub_task.reseau
  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.
I tried add [Primary Key] to sub_TaskID  in the stored procedure , as it is the primary key for the table.

Peter
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros