저는 Entity Framework가 처음이므로 다음 쿼리에서 데이터를 추출하고 결과를보기에 전달하는 방법을 알려주십시오.Linq 쿼리에서 데이터를 추출하는 방법
public ActionResult Index()
{
var query = (from c in db.Customers
join b in db.Banks on c.Id equals b.CustomerId
join bt in db.BankTransactions on b.Id equals bt.BankId
where c.Id == 1
orderby bt.Id descending
select new
{
Name = c.Name,
Balance = bt.Balance
}).Take(1);
//I want to pass Customer Name and Customer Balance to the view
return View();
}
'return View (query.ToList());'? – artm
... 당신의 뷰가 IEnumerable을 모델로 받아 들일 만하다고 가정한다면'Return View (query.ToArray());'그렇지 않으면 익명의 타입을 사용하지 말아라 ... –
당신은'.ToList()'하지만, 원인, _deferred execution_. –