如何通过拖放绑定刷新包含数据库视图的WPF数据网格

本文关键字:WPF 数据 数据网 网格 视图 数据库 拖放 何通过 绑定 刷新 包含 | 更新日期: 2023-09-27 17:49:17

我有以下数据库结构:

Table:Books
Column: bookid;(PK)
Column: book_title;
Column: isbn;
Column: author_id;(FK)
Column: publisher_id;(FK)

上面的表通过外键与另外两个名为"publishers"answers"authors"的表连接。它们的定义如下:

Table:Publishers
Column: publisher_id;(PK)
Column: publisher_title;

Table:Authors
Column: Author_id;(PK)
Column: Author_title;

创建的数据库视图如下:

view:book_info
Column: bookid;
Column: book_title;
Column: isbn;
Column: publisher_title;
Column: Author_title;

现在我所做的是,我拖放这个视图作为数据网格在WPF窗口。我得到了所需视图。我试图使用一个简单的网格上绑定到表的可观察集合。现在如何在一个网格上使用这个可观察集合,它的ItemsSource作为数据库视图?

我还没有写任何代码,因为我仍然困惑我如何更新然后刷新这个网格?

如何通过拖放绑定刷新包含数据库视图的WPF数据网格

事情总是以意想不到的方式发生。我的朋友发现,即使进行了更新,实体也没有更新。所以我们创造了相同的新实体。参见下面的代码。

//the first declaration on the top.
bookDatabaseEntities bde = new bookDatabaseEntities();
//wrote this code where i need to assign itemssource.This will fetch updates and overwrite older entity created earlier.
bde = new bookDatabaseEntities();
//asssign new view to the grid as itemssource
joinViewsDataGrid.ItemsSource = bde.JoinViews;

这对我来说很有用。