Why is there no change in dbcontext.ChangeTracker when loading a collection from encore dbcontext with tracking changes to DataSource?

I have 'List GridData { get; set; }' and ''

In method 'OnInitialized' i do 'GridData = await _dbContext.Users..Include(au => au.Roles).ToListAsync();'

Why in method 'BatchSave' when i doing '_dbContext.SaveChangesAsync()' - '_dbContext.ChangeTracker' not have changes?

What kind of stupid logic is this???

I will immediately note that the example you gave of "Creating a Data Access Layer" is absolutely useless, since there is no need to create separate repositories for DbContext.


1 Reply

RN Rahul Narayanasamy Syncfusion Team October 25, 2021 03:56 AM UTC

Hi Alexey, 

Greetings from Syncfusion. 

We have validated your query and we are quite unclear about your requirement. Also we suspect that you want to get the edited data while saving changes in Grid. If yes, then you get the edited data using GetBatchChangesAsync method of the Grid. You can get the edited data using GetBatchChangesAsync method and update the data to your database

 
<SfGrid @ref="GridInstance" DataSource="@Orders" Toolbar="@(new List<string>() { "Add", "Delete", "Update", "Cancel" })"> 
    <GridEvents OnBatchSave="BatchSaveHandler" TValue="Order"></GridEvents> 
    <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Batch"></GridEditSettings> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> 
        <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn> 
        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
    </GridColumns> 
</SfGrid> 
 
@code{ 
    public List<Order> Orders { get; set; } 
     public SfGrid<Order> GridInstance { get; set; } 
 
    . . . 
 
    public async Task BatchSaveHandler(BeforeBatchSaveArgs<Order> args) 
    { 
        var changes = await GridInstance.GetBatchChangesAsync(); 
        // Here you can customize your code 
    } 
} 


If you are still facing any complexities, then could you please share the below details. It will be helpful to validate and provide a better solution. 

  • Full Grid code snippets.
  • Video demonstration of the problem.
  • Share a simple reproduceable sample if possible.
  • If you want to get the edited data and store to your database. Then you can get the edited data using GetBatchChangesAsync method and update the data to your database in OnBatchSave event.
  • Share more details about your requirement.

Regards, 
Rahul 
 


Loader.
Up arrow icon