1. Linq to Entities
using (TestEntities te = new TestEntities()) { var user = from a in te.User where a.UserDepartment.UserDepartment_name == "經理部" orderby a.User_id select a; }
lambda方式
using (TestEntities te = new TestEntities()) { var user = te.User.Where(a => a.UserDepartment.UserDepartment_name == "經理部") .OrderBy(a => a.User_id) .Select(a => a); }
2. Query Builder Mothed
using (TestEntities te = new TestEntities()) { var user = te.User.Where("it.UserDepartment.UserDepartment_name == \"經理部\"") .OrderBy("it.User_id"); }
3. Entity SQL Language
using (TestEntities te = new TestEntities()) { string entitySQL = "SELECT Value a FROM User as a"; entitySQL += " WHERE a.UserDepartment.UserDepartment_name == \"經理部\""; entitySQL += " Order by a.User_id"; var user = te.CreateQuery<User>(entitySQL); }
比较
Linq to Entities | Query Builder Mothed | Entity SQL Language | |
智能提示 | 0 | X | X |
设计期除错 | O | X | X |
动态查询 | X | O | O |
对Provider产生的SQL语法控制 | 一般 | 較好 | 最好 |
支持的函数式 | 一般 | 多 | 多 |
开发速度 | 最佳 | 一般 | 一般 |