How to force Entity Framework to always get updated data from the database?

前端 未结 5 1882
[愿得一人]
[愿得一人] 2020-12-07 21:44

I am using EntityFramework.Extended library to perform batch updates. The only problem is EF does not keep track of the batch updates performed by the library. So when I que

5条回答
  •  情话喂你
    2020-12-07 22:35

    I declared the entity variable, without assignment, as part of the class. This allowed me to dispose of an instance without losing the variable for reference by other methods. I just came across this so it doesn't have alot of runtime under it's belt, but so far it seems to be working fine.

    public partial class frmMyForm
    {
        private My_Entities entity;
    
        public frmMyForm()
        {
            InitializeComponent();
        }
    
        private void SomeControl_Click(object sender, EventArgs e)
        {
            db.SaveChanges();
            db.Dispose();
            entity = new My_Entities();
            //more code using entity ...
    }
    

提交回复
热议问题