No field update on edit

<PackageReference Include="Syncfusion.Blazor" Version="18.4.0.30" />


I am trying to use the datagrid in a blazor app, I have a Foreign key column called 



public class County{

        public int Id { get; set; }
        public string Name { get; set; }
}


On the razor page I have the following 

<SfGrid Toolbar="@ToolbarList" TValue="Structure" AllowPaging="true" AllowSorting="true" AllowFiltering="true" AllowGrouping="true">
        <SfDataManager Url="api/Structure" Adaptor="Adaptors.WebApiAdaptor"></SfDataManager>
        <GridEditSettings AllowAdding="@canedit" AllowDeleting="@canDelete" AllowEditing="@canedit" Mode="EditMode.Normal"></GridEditSettings>
        <GridColumns>
             <GridColumn Field=@nameof(Structure.Id) HeaderText="ID" IsPrimaryKey="true" TextAlign="@Syncfusion.Blazor.Grids.TextAlign.Right"                             Width="90">     </GridColumn>
            <GridColumn Field=@nameof(Structure.Direction) HeaderText="Direction"  TextAlign="@Syncfusion.Blazor.Grids.TextAlign.Right" Width="90">
           </GridColumn>
            <GridForeignColumn  TValue="County" Field=@nameof(Structure.CountyId) ForeignKeyField="Id" HeaderText="County" ForeignKeyValue="Name" Width="150">
                <SfDataManager Url="api/County" Adaptor="Adaptors.WebApiAdaptor" CrossDomain=true></SfDataManager>

            </GridForeignColumn>


            <GridColumn Field=@nameof(Structure.LastEditedBy) AllowEditing="false" HeaderText="LastEditedBy" Width="90"></GridColumn>
            <GridColumn Field=@nameof(Structure.LastEdit) AllowEditing="false" HeaderText="Last Edit Date" Width="90"></GridColumn>

        </GridColumns>
    </SfGrid>

This works perfect for displaying the data,

When adding new records the selected County is properly sent to the api along with other fields.

When Editing I can select a different County  but there is no change sent to the api for this field. 
All <column> fields update but not <GridForeignColumn>

Thanks in advance for your help




5 Replies 1 reply marked as answer

RS Renjith Singh Rajendran Syncfusion Team December 28, 2020 12:43 PM UTC

Hi Ed, 

Greetings from Syncfusion support. 

We tried to reproduce the reported problem by creating a sample based on this scenario. But we could not face the reported problem with the sample from our side. Please download the sample from the link below, 
 
Kindly refer the above attached sample and if you are still facing difficulties, then the following details would be helpful for us to proceed further. 

  1. Share a simple issue reproducing sample or if possible reproduce the issue with the above attached sample and share with us for further analysis.
  2. Share the exact scenario you are facing this reported problem.

Regards, 
Renjith Singh Rajendran 



ED Ed December 29, 2020 03:02 AM UTC

Hello Renjith Singh Rajendran,
     I have narrowed down when this error occurs.

 It happens when the Class Data in this case  IEnumerable<Structure> data sent to the page has the virtual class data in this case  County data included in the data object model. 

example:
            return _context.Structure
            .Include(y => y.County);

If I don nott .include the County data it The change to the foreignkey column is updated when the updated record is set to the api. But if the county data is included it wont update the data, it reverts back the the County data in the model before updating to the Api. Is there a setting to override this behavior?

Thanks Ed


JP Jeevakanth Palaniappan Syncfusion Team December 29, 2020 12:27 PM UTC

Hi Ed, 

Thanks for the update but we are quite unclear about the scenario you have explained. So could you please provide us the issue reproducing sample or reproduce the issue in the below provided sample. It will be helpful for us to validate the issue and provide you with a better solution as early as possible. 

Regards, 
Jeevakanth SP. 



ED Ed January 1, 2021 06:16 PM UTC

Hello Jeevakanth
I finally had time to get back to this today. I made a web assembly project based on  your webapi project that uses sql as a back end. I am uploading it. if you create the database and run this program you will see that when changing the employee Foreignkey column on the grid when editing it reverts back when updated. if you comment out the .Include(x => x.Employee)  on line 35 of the default controlled you will see that it will then work. I did track the error down to the fact that the foreignkey column updates the foreignkey but not the model. so when the record is saved back to sql the foreignkey is reset back to the one matching the model. I have made a work around for my project by setting the model to the matching foreignkey before saving. 

Thanks
Ed

Attachment: ApiForeignKeyNoUpdateOnEdit_5ea3f3a1.rar


RN Rahul Narayanasamy Syncfusion Team January 7, 2021 01:08 PM UTC

Hi Ed, 

Thanks for sharing the sample. 

We tried running the sample from our side to reproduce the problem, but we are facing some authentication problem with the sample and the DefaultController Get method itself is not triggered in the shared sample. 

So we tried the reported case scenario(if you comment out the .Include(x => x.Employee)  on line 35) with a hosted sample from our side. But the edit action works fine with the sample from our side. We are attaching the sample for your reference, please download the sample from the link below, 
 
We suspect that the problem might be with the edit handling method in DefaultController. And also ensure to have a unique valued primary key column in Grid, the editing update action will take place based on the unique valued primary key column. 
 
Kindly refer the above attached sample and ensure the above suggested cases and check for this case from your side. And if you are still facing difficulties, then kindly get back to us with the following details which would be helpful for us to proceed further. 

  1. Kindly reproduce the reported problem with the above attached sample and share with us for further analysis.
  2. Share with us the exact scenario your are facing this reported problem.

The provided information will help us analyze the problem, and provide you a solution as early as possible. 

Regards, 
Rahul  


Marked as answer
Loader.
Up arrow icon