声明实体框架命令或数据集(ado.net)以访问或操作 mvc 模式中的数据应该在模型中,正如我所知,当我想在数据库中获取我的对象列表时,所有方法都应该在模型中并返回列表,控制器只是应该得到它并将其传递给查看,
但正如我在控制器中使用的许多代码 decalaring 方法中看到的那样,例如^
//I get logged in user properties
var user = db.UserProperties.SingleOrDefault(x => x.UserName == User.Identity.Name);
Buddyship allBudees = db1.Buddyships.SingleOrDefault(u =>u.BuddiedByUserId == user.UserId);
var buds = from u in db.UserProperties
join m in db1.Buddyships on u.UserId equals m.BuddiedByUserId
where m.BuddiedByUserId == user.UserId
select new { u.FirstName, u.LastName, u.SchoolName, u.UserId };
var buddyviewmodel = new BuddyViewModel(buds //don't know what to put here);
return View(buddyviewmodel);
这部分代码应该在模型或控制器中?