EF 和 WPF Datagrid 绑定问题
是否可以动态更改 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧我发现了。
问题是该属性
正在调用
OnpropertyChanged
,而不是Base.OnPropertyChanged
。不知道为什么会这样,可能是因为事件没有被冒泡。
有人有答案吗?
Okay I found out.
The issue was that the property
is calling the
OnpropertyChanged
but not theBase.OnPropertyChanged
.Not sure why it works that way might be that the event is not being bubbled up.
Does anybody has an answer?