This article is a mirror article of machine translation, please click here to jump to the original article.

View: 19361|Reply: 0

[Source] Solved no left connection in linq

[Copy link]
Posted on 7/30/2015 10:28:24 AM | | |
UserID        UserName        DeptID        Password        Cellphone        UserType        DeptName
1030 Wang Yan 4 1 1 Supervision Department
2026 Li Wei 2 1 0 Training Center
3006 Li Kun 5 1 0 Wusoft Co-construction College
3009 Wang Peng 2 1 1 Training Center
3026 Qian Huan 5 1 1 Wusoft Co-construction College
3038 Chen Fengyun 6 1 0 Logistics Management Department
3044 Xia Xiaoshan 5 1 0 Wusoft Co-construction College
3045 Cheng Xianxiong 2 1 0 Training Center
3050 Li Ying 5 1 0 Wusoft Co-construction College
3053 Qu Yuan 4 1 0 Supervision Department
admin NULL 1 15888888888 2 NULL

sql statement: select u.*, d.DeptName from userinfo u left join Department d on u.deptid=d.deptid
If there is no left keyword in linq, how to solve it?
  1. var i = from u in db.UserInfo
  2.                     join d in db.Department on u.DeptID equals d.DeptID
  3.                     into temp from tt in temp.DefaultIfEmpty()
  4.                     select
  5.                         new Model.ModelUserInfo { UserID = u.UserID, UserName = u.UserName, DeptID = u.DeptID == null ? 0 : Convert.ToInt32(u.DeptID), DeptName = tt == null ? "" : tt.DeptName, Cellphone = u.Cellphone, UserType = Convert.ToInt32(u.UserType) };
Copy code

SQL is still simpler! !





Previous:In the asp.net, CheckBox selects 2 methods for all CheckBoxes
Next:Jquery gets the values of select, dropdownlist, checkbox drop-down list boxes
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com