CodeFluentEntityState保持Unchanged,求分析Statistic实体配置问题
Hey there, let's break down exactly why your Statistic entity's state is stuck in Unchanged—it's directly tied to the configuration flags you've set up.
First, let's look at your entity configuration snippet for reference:
<cf:entity name="Statistic" _fr:fastReader="true" setType="List" concurrencyMode="None" trackingModes="None" namespace="Runtime" categoryPath="/Compareware" persistenceName="Statistic"> <cf:property name="Date" trackingModes="None" key="true" typeName="date" /> <cf:property name="ResultViews" trackingModes="None" typeName="short" /> <cf:property name="Position" cfps:size="8,4" cfps:dataType="numeric" xmlns:cfps="http://www.softfluent.com/codefluent/producers/sql/2005/1" /> </cf:entity>
The Root Cause: Disabled Change Tracking
The main issue here is the trackingModes="None" setting applied both at the entity level and every property level:
- When you set
trackingModes="None"on an entity, CodeFluent completely turns off change tracking for that entire entity type. The framework won't monitor any property value changes, so it can never detect modifications and will always report the state asUnchanged. - Adding
trackingModes="None"to individual properties doubles down on this—even if you removed the entity-level setting, those specific properties wouldn't be tracked. - The
concurrencyMode="None"setting also contributes: while it's mainly about skipping concurrency checks, combined with disabled tracking, it removes any mechanism that might trigger a state update.
Fixes & Actionable Steps
If you need to modify and persist changes to this entity, here's how to fix the state tracking issue:
- Remove the entity-level
trackingModes="None"
Update your entity declaration to drop this attribute (or set it toAllif you want full tracking):<cf:entity name="Statistic" _fr:fastReader="true" setType="List" concurrencyMode="None" namespace="Runtime" categoryPath="/Compareware" persistenceName="Statistic"> - Delete property-level
trackingModes="None"
Remove this attribute from every property that needs to be tracked. For example:<cf:property name="Date" key="true" typeName="date" /> <cf:property name="ResultViews" typeName="short" /> - Check the FastReader setting (if needed)
The_fr:fastReader="true"flag uses a lightweight reader that doesn't track entities by default. If you need tracking for entities loaded via FastReader, you'll want to either use the standard entity loader instead, or explicitly enable tracking when fetching records. - Adjust concurrency mode (optional)
If you need concurrency checks later, you can switch toconcurrencyMode="Optimistic"(you'll need to add a timestamp/version property for this), but this isn't required to fix the state tracking problem itself.
A quick note: Disabling tracking is great for read-only scenarios where you don't need to save changes. But if you intend to modify this entity and persist those changes, tracking has to be enabled at either the entity or property level.
内容的提问来源于stack exchange,提问作者Peter de Bruijn

