Can someone help me understand this error? I'm getting it on the line new DbSet<Survey>();
in the block code
public DbSet<Survey> GetAllSurveys ( )
{
DbSet<Survey> AllSurveys = new DbSet<Survey>();
using ( SqlCommand cmd = new SqlCommand("GetAllSurveys", this._Conn) )
{
cmd.CommandType = CommandType.StoredProcedure;
this._Conn.Open();
using ( SqlDataReader dataReader = cmd.ExecuteReader() )
{
while ( dataReader.Read() )
{
Survey srv = new Survey { Id = dataReader.IsDBNull(0) ? default(int) : dataReader.GetInt32(0),
Title = dataReader.IsDBNull(1) ? String.Empty: dataReader.GetString(1) };
AllSurveys.Add(srv);
}
}
this._Conn.Close();
}
return AllSurveys;
}
What's strange is that I'm not getting it when I create a DbSet<T>
right below:
public DbSet<Question> GetQuestionsBySurveyId ( int survid )
{
SqlCommand cmd = new SqlCommand("GetQuestionsBySurveyId", this._Conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", survid);
this._Conn.Open();
DbSet<Question> TheseQuestions = (DbSet<Question>)cmd.ExecuteScalar();
this._Conn.Close();
return TheseQuestions;
}
has no errors associated with it. What's the difference between these two?