SFDataManager Custom Binding Never Triggering Add or Update

When creating a custom DataAdaptor to manage CRUD operations I can get the read and delete functionalities to behave as expected, but the update and delete are never even being triggered. I've placed a breakpoint just inside the insert override method, but I never hit it in runtime. The update toolbar button flashes a loading circle then doesn't even escape out of the edit. I have to cancel the operation each time and my database never receives the update or addition.


SFDataGrid code:

            <SfGrid DataSource="@titles" AllowSorting="true" AllowExcelExport="true" Toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel", "Search" })">
                <GridEditSettings AllowEditing="true" AllowDeleting="true" AllowAdding="true" AllowEditOnDblClick="false" Mode="EditMode.Normal"></GridEditSettings>
                <SfDataManager AdaptorInstance=@typeof(EmployeeTitlesAdaptor) Adaptor="Adaptors.CustomAdaptor"></SfDataManager>
                <GridColumns>
                    <GridColumn Field=@nameof(IEmployeeTitleModel.Id) IsPrimaryKey="true" Visible="false" HeaderText="Id" TextAlign="TextAlign.Right"/>
                    <GridColumn Field=@nameof(IEmployeeTitleModel.Title) HeaderText="Employee Title" TextAlign="TextAlign.Right" EditType="EditType.DefaultEdit"/>
                    <GridColumn Field=@nameof(IEmployeeTitleModel.BillRate) HeaderText="Bill Rate" Format="C2" TextAlign="TextAlign.Right" EditType="EditType.NumericEdit" />
                </GridColumns>
            </SfGrid>


Custom Adaptor Class:

 public class EmployeeTitlesAdaptor : DataAdaptor
        {
            private readonly ISqlDataAccess _dataAccess;
            private IEmployeeDataService _employeeData;

            public EmployeeTitlesAdaptor(ISqlDataAccess dataAccess)
            {
                _dataAccess = dataAccess;
                _employeeData = new EmployeeSqlDataService(_dataAccess);
            }

            public override async Task<Object> InsertAsync(DataManager dataManager, object data, string key)
            {
                IEmployeeTitleModel title = titles.Where(x => x.Id == (data as IEmployeeTitleModel).Id).FirstOrDefault();
                if (title != null)
                {
                    await _employeeData.CreateEmployeeTitle(title);
                    titles.Insert(0, title as IEmployeeTitleModel);
                }
                return data;
            }


            public override async Task<object> UpdateAsync(DataManager dataManager, object data, string keyField, string key)
            {
                var val = (data as IEmployeeTitleModel);
                IEmployeeTitleModel title = titles.Where(x => x.Id == val.Id).FirstOrDefault();
                if (title != null)
                {
                    await _employeeData.UpdateEmployeeTitle(title);
                }
                return data;
            }


            public override async Task<object> RemoveAsync(DataManager dataManager, object data, string keyField, string key)
            {
                IEmployeeTitleModel t =  await _employeeData.ReadEmployeeTitles( (int)data);
                await _employeeData.DeleteEmployeeTitle(t);
                titles.Remove(titles.Where(x => x.Id == t.Id).FirstOrDefault());
                return data;
            }


ConfigureServices code:


            services.AddSyncfusionBlazor();
            services.AddScoped<EmployeeTitlesAdaptor>();
            services.AddScoped<IEmployeeDataService, EmployeeSqlDataService>();
            services.AddSingleton<ISqlDataAccess, SqlDataAccess>();



11 Replies

RS Renjith Singh Rajendran Syncfusion Team April 27, 2020 02:40 PM UTC

Hi Brandon, 

Thanks for contacting Syncfusion support. 

We have analyzed your codes, we suspect that using the DataSource property in your code might have caused the problem you are facing. It is not recommended to use the DataSource property in Grid when using binding CustomAdaptor for Grid. So we suggest you to try running your codes by removing the DataSource property and adding the TValue property instead.  We suggest you to refer our online documentation and use the codes in your application by referring the below documentation, 

Please refer the code below, 

 
<SfGrid DataSource="@titles" TValue="IEmployeeTitleModel" AllowSorting="true" AllowExcelExport="true"...> 
    ... 
</SfGrid> 


Query : I can get the read and delete functionalities to behave as expected, but the update and delete are never even being triggered. I've placed a breakpoint just inside the insert override method, but I never hit it in runtime 
And also we are not clear about this query. Is all the three CRUD methods(InsertAsync, RemoveAsync, UpdateAsync) not getting triggered or only the UpdateAsync/InsertAsync not triggered? 

Please try the above suggested solution from your side and modify your codes based on the online documentation codes, and if you are still facing difficulties, then kindly get back to us with the following details for better assistance. 
  1. Share a simple issue reproducing sample for us to validate further.
  2. Share the details of script error or exception if any occurred during Update/Insert/Delete actions.
  3. Share with us the clear description about the problem you are facing.
  4. Share a video demo showing the problem.

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

Regards, 
Renjith Singh Rajendran 



BS Brandon Schafer May 1, 2020 05:05 AM UTC

Hi Renjith,

You're suggestion helped get me down the right path and expose a few more flaws I had in my adaptor class. I've now been able to break out my adaptor into its own class and make all the appropriate calls to the database.

Thanks for the helpful advice!


TA Tarik Alkathiri replied to Brandon Schafer May 1, 2020 09:43 PM UTC

Hi Renjith,

You're suggestion helped get me down the right path and expose a few more flaws I had in my adaptor class. I've now been able to break out my adaptor into its own class and make all the appropriate calls to the database.

Thanks for the helpful advice!

Could you please share a sample of your solution
Thank you very much for your co operate.


RS Renjith Singh Rajendran Syncfusion Team May 4, 2020 11:41 AM UTC

Hi Brandon, 

Thanks for your update. We are glad to hear that our suggestion helped you in achieving your requirement. 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 



RS Renjith Singh Rajendran Syncfusion Team May 4, 2020 11:42 AM UTC

Hi Tarik, 

We have prepared a sample based on the above suggestion for your convenience. Please download the sample from the link below, 
And also we suggest you to refer to our documentation for more details regarding this topic, 
 
Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 



TA Tarik Alkathiri May 5, 2020 07:32 PM UTC

Thank you very much for the sample.
Best Regards.


TA Tarik Alkathiri replied to Renjith Singh Rajendran May 6, 2020 12:42 AM UTC

Hi Tarik, 

We have prepared a sample based on the above suggestion for your convenience. Please download the sample from the link below, 
And also we suggest you to refer to our documentation for more details regarding this topic, 
 
Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 


Dear Renjith Singh Rajendran,
I apply the sample you provided (which is good sample)
I needed to inject my service in the adapter constructor like the following

 
public class OwnerListAdaptor : DataAdaptor
        {
            private readonly IOwnerService _ownerService;

            public OwnerListAdaptor(IOwnerService OwnerService)
            {
                _ownerService = OwnerService;
            }
}
but at run time it gives me the error that say (No parameterless constructor defined for type) and the name of my adapter.
Did i missed any thing, Please help.
I am using this version (Syncfusion.Blazor" Version="18.1.0.45")
Thank you very much for your co operate.




TA Tarik Alkathiri May 6, 2020 01:58 AM UTC

I am very sorry for disturbance, please disregard my previous post as it was my mistake that i did not register the adapter in the setup.
Thank you very much for your co operative.


RN Rahul Narayanasamy Syncfusion Team May 6, 2020 05:21 AM UTC

Hi Tarik, 

Thanks for the update. 

We are happy to hear that you have found the cause by yourself. Please get back to us if you need further assistance. 

Regards, 
Rahul 



TY Tyrone April 22, 2021 07:26 AM UTC

Dear Renjith Singh Rajendran,

I'm having a same problem with Tarik's. 
returns the same error.

MissingMethodException: No parameterless constructor defined for type 'InventoryManagement.Web.Controller.AreaAdaptor'. 

on this Constructor 


        public IAreaService _AreaService;

        public AreaAdaptor(IAreaService areaService)
        {
            _AreaService = areaService;
        }

As he mentioned. The solution is to "Register the adapter in the setup"


How would I do that? can y0u provide me the steps.

Thanks




RN Rahul Narayanasamy Syncfusion Team April 23, 2021 01:43 PM UTC

Hi Tyrone, 

Greetings from Syncfusion. 

We have validated your query and you need to register the CustomAdaptor class in StartUp.cs file like below. Find  the below code snippets for reference. 

public void ConfigureServices(IServiceCollection services) 
        { 
            services.AddRazorPages(); 
            services.AddServerSideBlazor(); 
            services.AddSyncfusionBlazor(); 
            services.AddSingleton<WeatherForecastService>(); 
 
            services.AddScoped<OrderDataAdaptor>(); 
        } 

Reference

And we suspect that you have not defined any parameter-less constructor for your CustomAdaptor class. So define parameter-less constructor for your CustomAdaptor class and ensure the problem at your end. 

public IAreaService _AreaService; 
        //define parameter-less constructor
        public AreaAdaptor()
 
        { 
        } 
 
        public AreaAdaptor(IAreaService areaService) 
        { 
            _AreaService = areaService; 
        } 


Please let us know if you have any concerns. 

Regards, 
Rahul 


Loader.
Up arrow icon