I work in asp mvc 3 app. I have a model / object called "History". I have a linq query that returns a single value. Depending on what I am doing, I either get the error message "The object is not set to an instance" in the controller when the method is called, or I get "cannot implicitly convert the string from string to Models.History type". So Iām looking for help in resolving, do I just need to give it up or something?
Here is the method that gives the error "object not installed":
public string GetPastAbuseData(int Id) { var query = (from h in _DB.History where h.ApplicantId.Equals(Id) select h.AbuseComment).FirstOrDefault(); return query.ToString(); }
controller: vm.HistoryModel.AbuseComment = repo.GetPastAbuseData (Id);
And if I change the type of the method from a string to "History", I get the error "can not convert":
public History GetPastAbuseData(int Id) { return (from h in _DB.History where h.ApplicantId.Equals(Id) select h.AbuseComment).SingleOrDefault(); }
Thank you for your time.
source share