The sfgrid sends a patch request, passes the id and only the fields that were modified to the api (ODataV4Adaptor) which is good, but I am trying to figure out how to handle that properly in c# on the server.
I have a standard controller / repo / mysqldbcontext setup - the controller receives in a 'User' object in this case and that means all the other properties are null except for int or similar properties.
This means when _context.Users.Update(user); _context.SaveChanges(); is called it passes more than just the modified field(s) and it overwrites other fields with null.
How can I dynamically update based on the fields coming in?
Update on this - I managed to get it working through swagger by adding an indexer getter/setter to my class (below) and in the api repo I loop through the fields and set them. HOWEVER, now I am receive a binding error I assume from the sfgrid:
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100] Unhandled exception rendering component: Cannot bind to the target method because its signature is not compatible with that of the delegate type.
public object this[string propertyName]
{
get
{
Type myType = typeof(User);
PropertyInfo myPropInfo = myType.GetProperty(propertyName);
return myPropInfo.GetValue(this, null);
}
set
{
Type myType = typeof(User);
PropertyInfo myPropInfo = myType.GetProperty(propertyName);
myPropInfo.SetValue(this, Convert.ChangeType(value, myPropInfo.PropertyType), null);
}
}
Hi Scott,
Before proceeding with the reporting problem, we require some additional
clarification from your end. Please share the below details to proceed further
at our end.
Above-requested details will be very helpful in validating the reported query at our end and providing a solution as early as possible.
Regards,
Prathap S
I have attached a test project that duplicates the issue - go to the 'test weather service page' - the top grid loads data using a simple static object and the bottom grid loads using a custom adapter. I dont think the method of loading matters - its the difference in the WeatherForecast object. One has an 'indexer' the other does not - I am trying to use the indexer so I can dynamically get and set properties using string variables and the binding in the sfgrid does not seem to like it being there.
We would like to clarify that
the object type is not supported for the grid. Please note that our Grid
component requires strongly typed objects or POCO object-type data for binding.
This means that data binding must be based on a specific model type (class).
This behavior is inherent to the default functionality of the grid. If the
model type is unknown, we recommend using ExpandoObjectBinding or
DynamicObjectBinding. For more information on these binding options, please
refer to the following documentation link:
https://blazor.syncfusion.com/documentation/datagrid/columns#expandoobject-complex-data-binding
https://blazor.syncfusion.com/documentation/datagrid/columns#dynamicobject-complex-data-binding