简体   繁体   中英

Entity Framework: reload data if changes are occurred

I need to load data from SQL Express and keep them valid.

This code loads data after 1sec sleep. No matter is there changes or not.

static void Main(string[] args)
{
    while (true)
    {
        ReloadData();   

        Thread.Sleep(1000);
    }
}

static void ReloadData()
{
    using (var db = new ProverkaEntities())
    {
        var ls = db.texts.ToList();
        foreach (var s in ls)
        {
            Console.WriteLine(s.text);
        }
        Console.WriteLine("======");
    }
}

Is there some way to reload data only if changes are occurred?

The truth is out there: How to use SqlDependency to get the notification in Entity Framework

Don't forget to enable Service Broker in your Db properties!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM