none
Operation is not valid due to the current state of the object.

    Question

  • I am trying to do a very simple thing...

            public InitialIEPResponse CancelAllIEPs(string localStudentId)
            {
                var response = new InitialIEPResponse { Success = true };
                int cancelled = _IEPService.GetStatusByName("Cancelled").Id;
    
                var ieps = Context.Star_SpecialEd_IEPs.Where(iepI => iepI.LocalStudentId == localStudentId).Select(iepI => iepI.Id).ToList();
                var iepInstances = Context.Star_SpecialEd_IEP_Instances.Where(iepI => ieps.Contains(iepI.IepId)).ToList();
    
                foreach (Star_SpecialEd_IEP_Instance item in iepInstances)
                {
                    item.StatusId = cancelled;
                    item.EditedDate = DateTime.Now;
                    item.EditedBy = "John";
                }
    
                return response;
            }

    But I get this error when it tries to set item.StatusId.  It is a field in the DB that is also a FK. If I comment out the setting of the FK it works fine.

    PLEASE HELP.



    Thanks JD LinkedIn: www.linkedin.com/in/johndsanders

    Friday, December 06, 2013 7:56 PM

Answers

  • OK Figured it out but have no idea why it works.

            public InitialIEPResponse CancelAllIEPs(string localStudentId, string userName)
            {
                var response = new InitialIEPResponse { Success = true };
                var cancelled = _IEPService.GetStatusByName("Cancelled");
    
                var ieps = Context.Star_SpecialEd_IEPs.Where(iepI => iepI.LocalStudentId == localStudentId).Select(iepI => iepI.Id).ToList();
                var iepInstances = Context.Star_SpecialEd_IEP_Instances.Where(iepI => ieps.Contains(iepI.IepId)).ToList();
    
                foreach (Star_SpecialEd_IEP_Instance item in iepInstances)
                {
                    item.Star_SpecialEd_Lookup_Status = cancelled;
                    item.EditedDate = DateTime.Now;
                    item.EditedBy = userName;
                }
    
                Context.SubmitChanges();
                return response;
            }


    Thanks JD LinkedIn: www.linkedin.com/in/johndsanders

    Friday, December 06, 2013 9:17 PM

All replies

  • OK Figured it out but have no idea why it works.

            public InitialIEPResponse CancelAllIEPs(string localStudentId, string userName)
            {
                var response = new InitialIEPResponse { Success = true };
                var cancelled = _IEPService.GetStatusByName("Cancelled");
    
                var ieps = Context.Star_SpecialEd_IEPs.Where(iepI => iepI.LocalStudentId == localStudentId).Select(iepI => iepI.Id).ToList();
                var iepInstances = Context.Star_SpecialEd_IEP_Instances.Where(iepI => ieps.Contains(iepI.IepId)).ToList();
    
                foreach (Star_SpecialEd_IEP_Instance item in iepInstances)
                {
                    item.Star_SpecialEd_Lookup_Status = cancelled;
                    item.EditedDate = DateTime.Now;
                    item.EditedBy = userName;
                }
    
                Context.SubmitChanges();
                return response;
            }


    Thanks JD LinkedIn: www.linkedin.com/in/johndsanders

    Friday, December 06, 2013 9:17 PM
  • Hello,

    What is the error message if you set

     item.StatusId = cancelled;
    Friday, January 03, 2014 7:59 AM