I have been looking on Stack overflow but none of the answers seem to fully sort out this problem. The error I'm getting is:
Cannot initialize type 'mvcTest.Models.MakeModelSpec' with a collection initializer because it does not implement 'System.Collections.IEnumerable'
I have created a new type like this to get over the anonymous type error
public class MakeModelSpec
{
public int MakeId { get; set; }
public string Name { get; set; }
}
public IQueryable<MakeModelSpec> GetSpecs(int makeid)
{
var searchspec = from spec in db.Specs
join model in db.Models on spec.ModelID equals model.ModelID
join make in db.Makes on model.MakeID equals make.MakeId
select new MakeModelSpec
{
make.MakeId,
spec.Name,
};
if (makeid != -1)
{
searchspec = searchspec.Where(make => make.MakeId == makeid);
}
return searchspec;
}
If anyone can point me in the right direction, I would be very grateful I'm using MVC c# and a sql server db