TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Bill Dickinson
NA
1
1.7k
Initializing WPF Datagrid bound to ling to sql dbml
Nov 18 2013 11:13 PM
I have a case in which data external to a database is displayed in a WPF DataGrid. Currently, the data comes in as an ObservableCollection of type T, where each T is a class that models a database table.
Some of the data may already exist in the database table, but some may be new and will not be stored in the database. The DataGrid provides a way of editing/adding new items to the table and viewing those items that have already been analyzed (they exist in the database).
So, here's my problem - I would like to use Linq to SQL to create a dbml datacontext on the table for CRUD operations. However, the data coming in when the grid is loaded is not from the database. I check the database for items that match what's in the ObservableCollection and highlight them in the grid to indicate that they already exist, and to highlight those items in the ObservableCollection that are not in the database.
My first inclination is to bind the DataGrid to the ObservableCollection on the load operation, and then switch the context to the dbml datacontext after the grid is loaded. From that point forward, I would expect the CRUD operations to make their way to the database.
Is this a reasonable approach? I bet there's something better and I would appreciate feedback on how best to tackle this problem. Thanks.
Reply
Answers (
0
)
How to Draw WindRose using in WPF
dont show save file window