I have the following model in my asp mvc application
public class StringIntType
{
public string str { get; set; }
public int nbr { get; set; }
public string par { get; set; }
public DateTime date { get; set; }
}
I run this query
var sql = "select object as str , host as par from table " +
"where date > '2015-01-01' and date <'2015-01-03' option (recompile)";
and map results into this list
var myList = (List<StringIntType>)db.Database.SqlQuery<StringIntType>(sql).ToList();
The problem is when i try to do some sorting in myList that way
int n = myList.Where(x => x.par.Contains("object")).Count();
I get the following error
Object reference not set to an instance of an object at x.par.Contains("object")
myListisnullthats why. Perform a null check before directly manipulating itx.paris null