|
|
|
C# .Net ขอคำปรึกษา/สอบถาม การแปลง Entity Framework to SQL หน่อยครับ (มี Code ด้านใน) |
|
|
|
|
|
|
|
Code (C#)
/// <summary>
/// Get All Users
/// </summary>
/// <returns>List<Users>()</Users></returns>
[HttpGet]
[Route("GetAllUsers")]
public async Task<List<Users>> GetAllUsers() {
var lstUser = new List<Users>();
using (var cn = SexyDatabase.SexyConnection(forceOpen: true)) {
cn.ChangeDatabase("FuckerConfigDB"); // Fly with imagine.
try {
var tmp1 = await cn.GetListAsync<Users>();
//var tmp2 = await cn.GetListAsync<Users>(new { UserCode = "Fucker"});
// tmp2 SQL Raw : select * from Users where UserCode = 'Fucker'
lstUser = tmp1.ToList();
}
catch (Exception ex) {
Console.WriteLine(ex.Message);
}
}
return lstUser;
}
ปล. อะไรที่ไม่มีเช่น select 1234 as xCount from... ก็ให้ใช้ dynamic IList
|
|
|
|
|
Date :
2021-02-05 07:45:16 |
By :
ผ่านมา |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
// ผู้ป้อนข้อมูล (Table Users)
wlsAjaxHandler.execute("GET", "/api/Security/GetAllUsers", null, function (res) {
let tmp = null;
let he = $('#cboZUser');
he.empty();//.trigger("change");
var options = he.get(0).options;
options[options.length] = new Option(CUR_LANG != 'en' ? "ทุกท่าน" : "All Users", "");
tmp = he.select2({
width: "100%",
data: $.map(res, function (obj) {
let tmpDesc = (CUR_LANG != "en") ? obj.username : obj.usernameus;
obj.id = obj.id || obj.usercode; // replace pk/value with your identifier
obj.text = obj.text || tmpDesc;
return obj;
}),
});
}, (error) => { alert(error);});
ตัวอย่าง ComboBox Users
|
|
|
|
|
Date :
2021-02-05 08:02:54 |
By :
ผ่านมา |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|