ASP-.NET在MVC中使用LINQ实现多表联查_第1页
ASP-.NET在MVC中使用LINQ实现多表联查_第2页
ASP-.NET在MVC中使用LINQ实现多表联查_第3页
ASP-.NET在MVC中使用LINQ实现多表联查_第4页
ASP-.NET在MVC中使用LINQ实现多表联查_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1 使用到的数据库 2 程序文件 a Model teacherModel cs 3 using System 4 using System Collections Generic 5 using System ComponentModel DataAnnotations 6 using System ComponentModel DataAnnotations Schema 7 using System Data Entity 8 using System Globalization 9 using System Web Security 10 using System Data SqlClient 11 using MvcApplication3 publicclass 12 using System Linq 13 14 15 namespace MvcApplication3 Models 16 17 18 public class TeacherDbContext DbContext 19 20 public TeacherDbContext 21 base TeacherDbContext 22 23 24 public DbSet teachers get set 25 public DbSet tasks get set 26 27 28 29 30 Table teacherInfo 31 public class teacherInfo 32 33 Key 34 DatabaseGeneratedAttribute DatabaseGeneratedOption Identity 35 public string tid get set 36 37 Required 38 Display Name 用户名 39 public string userName get set 40 41 Required 42 Display Name 密码 43 public string pwd get set 44 45 Required 46 Display Name 姓名 47 public string name get set 48 49 Required 50 Display Name 性别 51 public string xingbie get set 52 53 Required 54 Display Name 系部 55 public string xibu get set 56 57 Required 58 Display Name 电话 59 public string phone get set 60 61 Table task 62 public class task 63 64 Key 65 DatabaseGeneratedAttribute DatabaseGeneratedOption Identity 66 public string id get set 67 68 Required 69 Display Name 作业 70 public string zuoye get set 71 72 Required 73 Display Name 教师编号 74 public string tid get set 75 76 77 78 Required 79 Display Name 次数 80 public string countnumber get set 81 82 Required 83 Display Name 识别码 84 public string keytodiff get set 85 86 87 88 public class teacherAndTask 89 90 91 public string userName get set 92 93 94 public string pwd get set 95 96 97 public string name get set 98 99 100 public string xingbie get set 101 102 103 public string xibu get set 104 105 106 public string phone get set 107 108 109 public string id get set 110 111 112 public string zuoye get set 113 114 115 public string tid get set 116 117 118 119 public string countnumber get set 120 121 122 public string keytodiff get set 123 124 125 126 127 public class Login 128 129 DBClass dbObj 130 public Login 131 132 dbObj new DBClass 133 134 135 136 a View Index cshtml 137 model IEnumerable 138 139 using System Collections 140 using MvcApplication3 Models 141 142 143 ViewBag Title Index 144 TeacherDbContext db new TeacherDbContext 145 146 147 148 Index 149 150 151 Html ActionLink Create New Create 152 153 154 155 156 Html DisplayNameFor model model userName 157 158 159 Html DisplayNameFor model model pwd 160 161 162 Html DisplayNameFor model model name 163 164 165 Html DisplayNameFor model model xingbie 166 167 168 Html DisplayNameFor model model xibu 169 170 171 Html DisplayNameFor model model phone 172 173 174 Html DisplayNameFor model model zuoye 175 176 177 Html DisplayNameFor model model tid 178 179 180 Html DisplayNameFor model model countnumber 181 182 183 Html DisplayNameFor model model keytodiff 184 185 186 187 188 foreach var item in Model 189 190 191 192 Html DisplayFor modelItem item userName 193 194 195 Html DisplayFor modelItem item pwd 196 197 198 Html DisplayFor modelItem item name 199 200 201 Html DisplayFor modelItem item xingbie 202 203 204 Html DisplayFor modelItem item xibu 205 206 207 Html DisplayFor modelItem item phone 208 209 210 Html DisplayFor modelItem item zuoye 211 212 213 Html DisplayFor modelItem item tid 214 215 216 Html DisplayFor modelItem item countnumber 217 218 219 Html DisplayFor modelItem item keytodiff 220 221 222 Html ActionLink Edit Edit new id item id 223 Html ActionLink Details Details new id item id 224 Html ActionLink Delete Delete new id item id 225 226 227 228 229 a Controler TTController cs 230 using System 231 using System Collections Generic 232 using System Data 233 using System Data Entity 234 using System Linq 235 using System Web 236 using System Web Mvc 237 using MvcApplication3 Models 238 239 namespace MvcApplication3 Controllers 240 241 public class TTController Controller 242 243 private TeacherDbContext db new TeacherDbContext 244 245 246 GET TT 247 248 public ActionResult Index 249 250 251 var temp from a in db tasks 252 join b in db teachers 253 on a tid equals b tid 254 select 255 new teacherAndTask 256 257 userName b userName 258 pwd b pwd 259 name b name 260 xingbie

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论