C#C
C#14mo ago
Saiyanslayer

✅ Better way to set a property using linq?

I have this on a blazor component:
 ValueChanged=@( async text => {
            protocol.maxIterations = text;
            await OnProtocolChanged(protocol);
        })


to set a property, I had first set the property on the class and then feed that class to the update method.

I want to streamline the process to something similar to how EF Core sets a property in ExecuteUpdate:
 ValueChanged=@(async text => await OnProtocolChanged(protocol.SetValue(x => x.maxIterations, text)


looks like EF Core uses this SetPropertyCall class:
https://github.com/dotnet/efcore/blob/2e9e879746c3a75ad71b1c3732469c25f01bb8c7/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs#L3338
https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.query.setpropertycalls-1.setproperty?view=efcore-8.0

When I inspected the class on github, I couldn't find anything substantive that I could parse.

The best I could do is this:
ValueChanged=@( async text => await OnProtocolChanged(protocol.GetType().GetProperty("Location"), text))
Specifies a property and corresponding value it should be updated to in ExecuteUpdate method.
GitHub
EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations. - dotnet/efcore
Was this page helpful?