Using c#, net.4.5 vs 2012
I'm trying to get data from database using Entity Framework.
At first idea was use code like below - it's must allow to add, delete and update entries in dataGridView, and than just save changes using context.SaveChanges() (method from ObjectSet, if I'm not wrong)
using (LibraryEntities context = new LibraryEntities())
{
var query = (from c in context.Book select c).First();
DataGridView dgv = new DataGridView();
dgv.DataSource = context.Book;
}
Result - exception
Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported...
Then I try a little bit changed code:
using (LibraryEntities context = new LibraryEntities())
{
var query = (from c in context.Book select c).First();
DataGridView dgv = new DataGridView();
dgv.DataSource = query;
}
but have same issue with exception
Data binding directly to a store query (DbSet, DbQuery, DbSqlQuery) is not supported...
At last try to convert all to List():
using (LibraryLib.LibraryEntities context = new LibraryLib.LibraryEntities())
{
DataGridView dgv = new DataGridView();
dgv.DataSource = (from c in context.Book select c).ToList();
}
As and expected, I got all db entries in DataGridView, but I can't add, update and delete any entries.

And the question is - how can I change db in dataGridView and than save it with DbContext.SaveChanges()
Hey. Try to consider the ready examples are not quite understand everythingDataGridViewВ останньому варіанті - все добре працює. Що хочу я - пернести всю базу даних доDataGridView. редагувати її (видаляти міняти значення додавати рядки. тощо). А потім повністю зберегти. Як це зробити?, адже спробувавши так як описано в книжці - видає виключення.DataGridView. what I want - it's to load all db inDataGridViewthan modify its entities and change them (mean add, del or update) and than just save it usingDbContext.SaveChanges()- like described in mny of tutorials that i seen - but i cant due to existing of exception