EF+MVC3的问题,连表的MODEL怎么用EF进行查询.
初次用EF和MVC3
我用的是CODE FIRST模式
现在有一个会议室MODEL 一个预定会议室的MODEL结构如下
[Key]
public int OrderId { get; set; }
[Required]
[Display(Name = "会议室")]
public int MeetingRoomId { get; set; }
[Required]
[Display(Name = "部门")]
public string OrderDept { get; set; }
[Required]
[Display(Name = "会议或培训内容")]
public string OrderName { get; set; }
public string EmpID { get; set; }
//[Required]
//[RegularExpression(@"^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\d):[0-5]?\d$", ErrorMessage = "日期时间不合法")]
//[RegularExpression(@"^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))?$", ErrorMessage = "日期时间不合法")]
[Display(Name = "开始时间")]
public DateTime OrderStartTime { get; set; }
//[Required]
[Display(Name = "结束时间")]
//[RegularExpression(@"^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(\s(((0?[1-9])|(1[0-2]))\:([0-5][0-9])((\s)|(\:([0-5][0-9])\s))([AM|PM|am|pm]{2,2})))?$", ErrorMessage = "日期时间不合法")]
//[RegularExpression(@"^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\d):[0-5]?\d$", ErrorMessage = "日期时间不合法")]
public DateTime OrderEndTime { get; set; }
[Required]
//[DefaultValue()]
[Display(Name = "每周会议")]
[Range(0,7)]
public int MeetingCycle { get; set; }
[Display(Name = "是否通过验证")]
public bool IsPass { get; set; }
public string Ip { get; set; }
[NotMapped]
public string EmpName { get; set; }
[NotMapped]
public string MeetingRoomName { get; set; }
最后我想在列表里加两个显示字段.选择不映射.但当我想联表查询时发现出错.不知道怎么解决.
var mo = from e in db.MeetingRooms
from f in db.MeetingOrders
from g in db.Admins
where e.MeetingRoomId == f.MeetingRoomId && f.EmpID == g.EmpDept
orderby f.OrderId descending
select new { e, f, g };
<