© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•16mo ago•
5 replies
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);
        })
 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)
 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))
ValueChanged=@( async text => await OnProtocolChanged(protocol.GetType().GetProperty("Location"), text))
SetPropertyCalls.SetProperty Method (Microsoft.EntityFrameworkCore....
Specifies a property and corresponding value it should be updated to in ExecuteUpdate method.
SetPropertyCalls.SetProperty Method (Microsoft.EntityFrameworkCore....
GitHub
efcore/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs ...
EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations. - dotnet/efcore
efcore/src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs ...
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

❔ using data received from a Post to determine what property to set
C#CC# / help
3y ago
Idiomatic LINQ way to access both object and an object's property? [Answered]
C#CC# / help
4y ago
Is there any way to *conditionally* set a property with EF `.ExecuteUpdateAsync()`?
C#CC# / help
3y ago