如何使用LINQ to SQL类的PropertyChangedEventHandler进行即时更新? [英] How to use PropertyChangedEventHandler of LINQ to SQL class for immediate updating?

查看:129
本文介绍了如何使用LINQ to SQL类的PropertyChangedEventHandler进行即时更新?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的WPF应用程序中,我实现了LINQ to SQL查询,该查询填充了与ListView连接的Observable集合.我可以从某处调用此方法,并且可以正常运行:

In my WPF app I have implemented LINQ to SQL query which populates an Observable Collection connected with ListView. It is in this method which I can call from somwhere and it works OK:

private void VisualizeAllShows()
{

    MyfirstdbDataContext context = new MyfirstdbDataContext();
    _ShowQuCollection.Clear();

    var sh = from p in context.Shows select p;

    foreach (var p in sh)  
      _ShowCollection.Add(new ShowsQu
        {
            Date = p.Date, 
            Time = p.Time, 
            Description = p.Description 
        });                 
}

现在,我需要在数据库表数据更改时自动进行此更新.

Now I need this updating to take place automatically on database table data changing.

为此,我应该在LINQ to SQL类中使用此公共事件:

Should I use for this purpose this public event in my LINQ to SQL class:

public event PropertyChangedEventHandler PropertyChanged;

如果是这样,请如何使用一个因数据更改而触发的事件处理程序? 如果没有,我应该在哪里寻找正确的方法?

If so, please, how to use an event-handler which would fire from data changing? If no, where I should look for right way to do this?

推荐答案

据我所知,数据库引擎没有任何东西可以通知您的应用程序对SQL Server上的表的更新.最好的选择是在SQL Server上使用CLR集成来添加它,请参阅#3.

As far as I know, there is nothing that comes from the database engine that notifies your application of updates to a table on the SQL server. Best bet is to add this using CLR integration on SQL Server, see #3.

这些是我能想到的选择: 1.通过重复查询数据库以检查更改来轮询更改. 2.我已经看到了SqlCacheDependancy用于此目的,但是从我的阅读来看,它是CPU密集型的. 3.将CLR程序集添加到已在触发器中实现代码的SQL Server中,以便更新然后运行.NET代码,该代码将通知您的应用程序更新.如果您能做到这一点,它可能是最有效的.我不确定在为SQL Server上的CLR集成编写.NET代码时,您有什么限制. IE.是否允许您连接到外部应用程序.在任何网络技术,TCP/IP,WCF,远程处理等方面,您的通信方式都可能会有所不同.

These are the options I can think of: 1. Poll for changes by querying the database repeatedly to check for changes. 2. I have seen SqlCacheDependancy used for this, but from what I read it was CPU intensive. 3. Add a CLR assembly to the SQL Server that has code implemented in a trigger, such that updates then run .NET code which notifies your application of the update. If you can get this to work it will probably be the most efficient. I'm not sure though what limitations you have when writing .NET code for a CLR Integration on SQL Server. I.e. whether or not it will let you connect to an external application. How you communicate could vary across any network technology, TCP/IP, WCF, Remoting, etc.

这篇关于如何使用LINQ to SQL类的PropertyChangedEventHandler进行即时更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆