Reputation: 87
Please help with below
I have Model
public class TitleView
{
public int Year;
public User User;
public IEnumerable<Students> Student;
public IEnumerable<Goal> Goals;
}
public class MyController: Controller
{
private Db db = new Db();
public ActionResult Index()
{
User User = new User();
Student Student= from a in db.Students where a.Name==User.Name select a;
error on this line, that cannot convert type IQueryable to Student.
var test= (from a in db.Goals where a.StudentID== Student.ID select a).ToList();
I can convert first line to List = .... ToList(); but then appear error on this line - with a.StudentID== Student.ID
var model = new TitleView()
{
User = User,
Student= Student
};
return View(model);
}
I know this is very simple
Upvotes: 0
Views: 54
Reputation: 7407
For getting a single instance from a list, you will need to call First
, FirstOrDefault
, Single
or SingleOrDefault
Read more about it here: http://www.dotnettricks.com/learn/linq/understanding-single-singleordefault-first-and-firstordefault
Upvotes: 2