I can add new row (item to list), by converting it to BindingList (simple list raises exception)
But when I save context - changes are not being committed / saved to DB
Can you please advise how to archive that?
My code:
// Flutent API var p_fluent = context.Products .Where (p => p.Price > 5) .OrderBy (p=> p.Name ).ThenBy(p => p.Id) .ToList(); var listBinding = new BindingList<Product> (p_linq.ToList ()); grdMain.DataSource = listBinding;
// Flutent API
var p_fluent = context.Products
.Where (p => p.Price > 5)
.OrderBy (p=> p.Name ).ThenBy(p => p.Id)
.ToList();
var listBinding = new BindingList<Product> (p_linq.ToList ());
grdMain.DataSource = listBinding;
Ive checked standard dataGridView - and same happens there, so this is not Infragistics - specific issue.
So this is more general and apparently lack of my experience with EF - seems this can be closed than
Thanks for reply Andrew.
Below what I get when click in new row using
grdMain.DataSource = p_fluent;
Unable to add a new row. Underlying DataSource does not support adding new rows
I dont have this error when:
var listBinding = new BindingList<Product> (p_fluent); grdMain.DataSource = listBinding;
(But then save doesnt commit changes to DB)
Hello Maciej,
Thank you for your post on this matter.
I believe the reason that your changes are not being committed or saved to the database is because you are creating a new instance of BindingList<Product> from your p_linq, so that is getting rid of the link to the context and you would need to push the updates back to the context this way. Some events on the grid that can help you do this could be the AfterCellUpdate/AfterRowUpdate.
I am curious of the exception you are seeing when trying to use a List in this case though, as this should be valid. Can you please provide some more information on that?