none
How to cast EntitySetBindingList

    Question

  • Hi,

    I have a grid binded to EntitySet<Class>, now i want to refresh the source.
    Normally when i want to refresh it, i will cast the data source

    dbManager.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, gridView.DataSource as List<ProdTransaction>);

    May i know to cast the data source when the source is EntitySet<Class>?

    From the error message, i found the source type is EntitySetBindingList, but when i put this keyword to code, it give syntax error. i already includes System.Data.Linq, but still have syntax error.

    Tuesday, September 24, 2013 10:22 AM

Answers

  • Hi,

    I have found a solution  to solve my problem.
    Actually i should change the title to how to refresh EntitySet.
    Because of my problem is the data in EntitySet is removed, but it is not committed to database yet, not in changeset as well, so i want to force the EntitySet to get latest from database.

    Below is my solution, although is not really good solution, but still able to solve my problem, not sure has any side effect yet.

    *VesselInfoDetails is my EntitySet

    item.VesselInfoDetails.Clear();
    item.VesselInfoDetails.AddRange(dataFromDatabase);
    Wednesday, September 25, 2013 5:42 AM

All replies

  • Hello,

    Welcome to this forum.

    Since I do not know how the grid is binded to EntitySet<Class>, so I guess that you have a DataGrid and it is binded to one entity, and you did some changes in the DataGrid, then you want to refresh the DataGrid with the data in database.

    If I guess correctly, maybe sample below will be helpful to you.

    using (DataClasses1DataContext db = new DataClasses1DataContext())
    
                {
    
                    DataGrid dataGrid1 = new DataGrid();
    
                    var orders = (from o in db.Orders
    
                                  select o).ToList();
    
                    for (int i = 0; i < orders.Count; i++)
    
                    {
    
                        orders[i].OrderName = "XXXXXXX";
    
                    }
    
                    dataGrid1.DataSource = orders;
    
                    db.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, dataGrid1.DataSource as List<Order>);
    
                }
    

    I query the Order entities collection from database, and the do some changes in it and then bind it to grid, and at last I refresh the grid with the data in database.

    So if it is possible, could you please share your code about this issue so that we can help you better.

    Thanks & Regards.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, September 25, 2013 3:26 AM
  • Hi,

    I have found a solution  to solve my problem.
    Actually i should change the title to how to refresh EntitySet.
    Because of my problem is the data in EntitySet is removed, but it is not committed to database yet, not in changeset as well, so i want to force the EntitySet to get latest from database.

    Below is my solution, although is not really good solution, but still able to solve my problem, not sure has any side effect yet.

    *VesselInfoDetails is my EntitySet

    item.VesselInfoDetails.Clear();
    item.VesselInfoDetails.AddRange(dataFromDatabase);
    Wednesday, September 25, 2013 5:42 AM