从SQL服务器数据库更新前端WPF应用程序

时间:2021-12-19 12:47:46

Please, help me clear my mind on the following question.

请帮我澄清一下我对以下问题的看法。

Recently I asked a question on SO, about possibility of immediate updating WPF classes from SQL Server DB through LINQ to SQL:

最近我问了一个关于SO的问题,关于从SQL Server DB到LINQ到SQL立即更新WPF类的可能性:

How to use PropertyChangedEventHandler of LINQ to SQL class for immediate updating?

如何使用LINQ的PropertyChangedEventHandler到SQL类进行即时更新?

from the answers I got know that this is rather complex issue and there is no easy way to know when and what exactly was changed in DB. The most common way is constant polling DB using a timer. (In answers were other ways of solving this issue but as workaround solutions, not always evident for developer).

从我得到的答案中,我知道这是一个相当复杂的问题,而且也没有简单的方法知道DB中什么时候以及什么地方发生了变化。最常用的方法是使用计时器来对数据库进行持续的轮询。(答案是解决这个问题的其他方法,但作为变通的解决方案,对开发人员来说并不总是明显)。

My question is (and I think this scenario is common to most of DB connected applications):

我的问题是(我认为这种情况在大多数DB连接的应用程序中很常见):

Imagine I have a table in a DB with 50'000 or 100'000 records from which I get a query.

假设我在DB中有一个表,其中有50,000或100,000个记录,从中我可以得到一个查询。

Using this query I should constantly update some visualization controls in my WPF app. So, does it mean that I should constantly make a query on this total number of records looking for one of them possibly changed (not just listening to some events about possible updating)? Is it common way to do this sort of things? Or maybe it is not a problem at all and such number of records is queried in milliseconds usually?

使用这个查询,我应该不断地更新我的WPF应用程序中的一些可视化控件。那么,这是否意味着我应该不断地对这些记录的总数进行查询,以查找其中一个可能更改的记录(而不仅仅是侦听一些可能更新的事件)?这是常见的做法吗?或者可能根本不是问题,这样的记录数通常以毫秒为单位进行查询?

2 个解决方案

#1


3  

You can include a timestamp field in your records, and create a trigger in the SQL server to update that timestamp on update or insert. In your refresh code, query the table for records with timestamp greater than the last refresh time.

您可以在记录中包含一个时间戳字段,并在SQL服务器中创建一个触发器来更新该时间戳,以更新或插入。在刷新代码中,查询表中记录的时间戳大于上一次刷新时间。

#2


2  

There is no way to have a database notify an application that does not involve some complicated communication between database and application. However application can easily notify each other that there has been a change you could use WCF to communicate between applications. Are you talking about a single application or several application that use the database?

没有办法让数据库通知不涉及数据库和应用程序之间复杂通信的应用程序。但是,应用程序可以很容易地通知彼此,您可以使用WCF在应用程序之间进行通信。您是在讨论一个应用程序还是几个使用数据库的应用程序?

What is your specific scenario? Are you concerned about concurrency?

你的具体场景是什么?您是否关心并发性?

#1


3  

You can include a timestamp field in your records, and create a trigger in the SQL server to update that timestamp on update or insert. In your refresh code, query the table for records with timestamp greater than the last refresh time.

您可以在记录中包含一个时间戳字段,并在SQL服务器中创建一个触发器来更新该时间戳,以更新或插入。在刷新代码中,查询表中记录的时间戳大于上一次刷新时间。

#2


2  

There is no way to have a database notify an application that does not involve some complicated communication between database and application. However application can easily notify each other that there has been a change you could use WCF to communicate between applications. Are you talking about a single application or several application that use the database?

没有办法让数据库通知不涉及数据库和应用程序之间复杂通信的应用程序。但是,应用程序可以很容易地通知彼此,您可以使用WCF在应用程序之间进行通信。您是在讨论一个应用程序还是几个使用数据库的应用程序?

What is your specific scenario? Are you concerned about concurrency?

你的具体场景是什么?您是否关心并发性?