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
    {
        [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.
User generated imageI tried add [Primary Key] to sub_TaskID  in the stored procedure , as it is the primary key for the table.

Peter
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
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

ASKER

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.

Thanks
Pete