Refresh ข้อมูลในกรณีที่ฐานข้อมูลมีการอัพเดทใน LINQ และ Entity Framework (Refresh Query in LINQ)
จากปัญหาที่เคยเจอในกรณีที่ฐานข้อมูลมีการอัพเดทไปแล้ว พอ Select ข้อมูลออกมาข้อมูลไม่ refresh ในกรณีนี้จะยกตัวอย่างการใช้งานฟังก์ชัน reload ของ System.Data.Entity.Infrastructure public class DbEntityEntry where TEntity : class // Summary:// Reloads the entity from the database overwriting any property values with values // from the database. The entity will be in the Unchanged state after calling this// method.public void Reload(); โดยการใช้งานนั้นจะยกตัวอย่างตามโค้ดด้านล่าง ProjectEntities pe = new ProjectEntities(); var project = pe.PROJECT.Where(w => w.ID == projectID && w.YEAR == year).FirstOrDefault(); if (project != null) { pe.Entry(project).Reload(); } หวังว่าคงจะได้ช่วยโปรแกรมเมอร์ทีมีปัญหาเรื่องการ refresh ข้อมูลผ่าน LINQ และ Entity Framework