EF 和 WPF Datagrid 绑定问题

发布于 2024-12-13 03:23:51 字数 1356 浏览 0 评论 0原文

是否可以动态更改 EF 连接到的服务器的名称?

我在 5 台服务器上有相同的数据库(不同的环境、开发、测试、UAT...),并且想编写一个仪表板应用程序,通过从 DDL 选择环境来依次从每台服务器提取相同的信息。

我正在使用实体框架 4/WPF/C#。新的 ObservableCollection(context.EntitySet) 绑定到 XAML 中的 WPF DataGrid。这很好用。 xaml 网格绑定在视图模型中如下所示

<grid:RadGridView ItemsSource="{Binding EPolicies}" IsReadOnly="True" RowDetailsVisibilityMode="VisibleWhenSelected" RowIndicatorVisibility="Collapsed" AutoGenerateColumns="False">

,我将以下代码

             entities = new EpolicyEntities(environmentConnStr);
            customTexts = new ObservableCollection<C_CustomTextType>(from i in entities.C_CustomTextType select i);
            languages = new ObservableCollection<C_Language>(from i in entities.C_Language select i);
            userTypes = new ObservableCollection<C_UserType>(from i in entities.C_UserType select i);
            EPolicies = new ObservableCollection<EPolicy>(from e in entities.EPolicies select e);

实体称为表示我连接到的数据库的 ObjectContext

第一次它工作正常,但第二次即使我可以看到 EPolicies 对象中的新值,网格没有像我想要的那样刷新 EPolicies 是定义如下的属性 公共 ObservableCollection 电子政策 { 获取{返回电子政策; } 放 { 电子保单 = 价值; OnPropertyChanged(() => EPolicies); } } 有人可以帮我吗? 谢谢

有人做过这个吗?

Is it possible to change the name of the server the EF connect to on the fly?

I have the same database on 5 servers (different environments, Dev, Test, UAT...) and would like to write a dashboard application to extract the same information from each server in turn by just selecting the environment from a DDL.

I am using Entity Framework 4/WPF/C#. The new ObservableCollection(context.EntitySet) is bound to the WPF DataGrid in XAML. This works fine.
the xaml grid binding is as follow

<grid:RadGridView ItemsSource="{Binding EPolicies}" IsReadOnly="True" RowDetailsVisibilityMode="VisibleWhenSelected" RowIndicatorVisibility="Collapsed" AutoGenerateColumns="False">

in the view model I call the following code

             entities = new EpolicyEntities(environmentConnStr);
            customTexts = new ObservableCollection<C_CustomTextType>(from i in entities.C_CustomTextType select i);
            languages = new ObservableCollection<C_Language>(from i in entities.C_Language select i);
            userTypes = new ObservableCollection<C_UserType>(from i in entities.C_UserType select i);
            EPolicies = new ObservableCollection<EPolicy>(from e in entities.EPolicies select e);

entities is the ObjectContext representing the database that I connect to

The first time it works fine but the second time even thoguh I can see the new values in the EPolicies object, the grid is not being refreshed as I would want
EPolicies is a property defined as below
public ObservableCollection EPolicies
{
get { return ePolicies; }
set
{
ePolicies = value;
OnPropertyChanged(() => EPolicies);
}
}
Can somebody help me please?
thanks

Anyone done this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独木成林 2024-12-20 03:23:51

好吧我发现了。

问题是该属性

public ObservableCollection EPolicies {                     

  get { return ePolicies; } 

  set {
      ePolicies = value; OnPropertyChanged(() => EPolicies); 
  }
}

正在调用 OnpropertyChanged,而不是 Base.OnPropertyChanged
不知道为什么会这样,可能是因为事件没有被冒泡。
有人有答案吗?

Okay I found out.

The issue was that the property

public ObservableCollection EPolicies {                     

  get { return ePolicies; } 

  set {
      ePolicies = value; OnPropertyChanged(() => EPolicies); 
  }
}

is calling the OnpropertyChanged but not the Base.OnPropertyChanged.
Not sure why it works that way might be that the event is not being bubbled up.
Does anybody has an answer?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文