public DoctorClass GetById(int id)
{
using (var context = new EmrContext())
{
var query = from d in context.Doctors
join c in context.Users on d.Id equals c.Id
where d.Id==id
select new DoctorClass { Email = c.Email, FirstName = c.FirstName, LastName = c.LastName, Post = d.Post };
return query;
}
}
下面是錯誤:無法隱式轉換類型 'System.Linq.IQueryable' 到 'Mvc.Models.DoctorClass'。存在明確的轉換(您是否缺少演員?)都轉換爲T
我需要用「查詢」來解決此問題嗎?
謝謝,我變得如此studid:/ – user2167382 2013-03-15 23:19:53
但如果查詢不包含元素? Single()填充返回異常? – user2167382 2013-03-15 23:26:43
那時SingleOrDefault可以派上用場。 – 2013-03-16 00:14:39