作为一个新手,我试图使用MVC3,剃须刀,EF我有三个连接表,我想从中产生一个视图。在一个愚蠢的简单,以下是对表MVC3 linq加入
PJUsers - ID,memUID(这种独特的会籍编号),名字,姓氏
PJAwards - 用户提名其他用户的一个奖项,以awardtypesID外国此链接键(awardId,布尔:awardok)
PJAwartypes - (awardtypeID,awardName)
在控制器查询是这样
var lists =
from tl in db.PJawards
join u in db.PJUsers on tl.nomineeId equals u.ID into tl_u
join i in db.PJUsers on tl.nominatorId equals i.MemUID into tl_i
where tl.awardOk
orderby tl.awardDated ascending
from u in tl_u.DefaultIfEmpty()
from i in tl_i.DefaultIfEmpty()
select new
{
Status = tl.awardOk,
nomineeFname = u.FirstName,
nomineeLname = u.LastName,
award = tl.PJawards.awardName,
Dated = tl.awardDated,
nominatorFname = i.FirstName,
nominatorLname = i.LastName,
nomineeCountry = u.Citizen,
nomineeResidence = u.Residence,
awardtypeId = tl.ID
};
某处我读,我要构建控制器
{
public class AwardUserInfo
{
public AwardUserInfo() { }
public bool Status { get; set; }
public string nomineeFname { get; set; }
public string nomineeLname { get; set; }
public string award { get; set; }
public string Dated { get; set; }
public string nominatorFname { get; set; }
public string nominatorLname { get; set; }
public string nomineeCountry { get; set; }
public string nomineeResidence { get; set; }
public int awardtypeId { get; set; }
}
}
请我学习的例子类似的查询模型类,以便能够帮助我以为我什么都不知道
请勿使用连接。如果你的EF模型是好的你可以管理没有他们(c) – Shymep