CodeFluentEntityState保持不变

时间:2018-04-16 09:21:31

标签: codefluent

我有一个具有以下配置的实体:

  <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.sqlserver/2005/1" trackingModes="None" typeName="float" />
<cf:property name="Detailviews" trackingModes="None" typeName="short" />
<cf:property name="Clicks" trackingModes="None" typeName="short" />
<cf:property name="CostTotalExclVat" cfps:size="8,2" cfps:dataType="numeric" xmlns:cfps="http://www.softfluent.com/codefluent/producers.sqlserver/2005/1" trackingModes="None" typeName="decimal" />
<cf:property name="SiteGuid" trackingModes="None" typeName="guid" />
<cf:property name="FormsSent" defaultValue="0" trackingModes="None" typeName="short" />
<cf:property name="FormsAccepted" trackingModes="None" typeName="short" />
<cf:property name="ObjectGuid" trackingModes="None" key="true" />
<cf:property name="Reveals" trackingModes="None" typeName="short" />
<cf:property name="ClusterAccountGuid" trackingModes="None" typeName="guid" />
<cf:property name="EndDate" trackingModes="None" typeName="date" />
<cf:property name="FormsSentNeedingAcceptance" trackingModes="None" typeName="short" />
<cf:property name="ClusterGuid" typeName="guid" />
<cf:method name="LoadBySiteClusterAccountAndDateSpan" body="LOAD ( SiteGuid, ClusterAccountGuid, Datetime DateFrom, Datetime DateTo) WHERE Date &gt;= @DateFrom AND Date &lt;= @DateTo AND ClusterAccountGuid = @ClusterAccountGuid AND SiteGuid=@SiteGuid  ORDER BY Siteguid ASC, Date ASC" />
<cf:method name="LoadBySiteClusterAccountAndDate" body="LOADONE (SiteGuid, ClusterAccountGuid, date) WHERE ClusterAccountGuid = @ClusterAccountGuid AND SiteGuid =@SiteGuid AND Date = @date" />
<cf:method name="LoadByUserAndDateSpan" body="LOAD (ClusterAccountGuid, Datetime DateFrom, Datetime DateTo) WHERE Date &gt;= @DateFrom AND Date &lt;= @DateTo AND ClusterAccountGuid = @ClusterAccountGuid ORDER BY Date ASC" />
<cf:method name="LoadByObjectAndDateSpan" body="LOAD(ObjectGuid, Datetime DateFrom, Datetime DateTo) WHERE Date &gt;= @DateFrom AND Date &lt;= @DateTo AND  ObjectGuid  = @ObjectGuid ORDER BY Date ASC" />
<cf:method name="LoadByObjectAndDate" body="LOADONE (ObjectGuid,Date ) WHERE Date =@Date AND ObjectGuid = @ObjectGuid" />
<cf:method name="LoadByCwSiteCluster" body="LOAD (ClusterGuid) WHERE ClusterGuid = @ClusterGuid" />

当我设置&#39; CostTotalExclVat&#39;对于现有项目,CodeFluentEntityState保持“未更改”状态。所以它不会保存更改。它可能与跟踪模式有关。&#39; trackingModes&#39;。但我不知道正确的设置。我不想要任何并发检查或_lastSave等。我做错了什么?

1 个答案:

答案 0 :(得分:1)

原因绝对是您在此属性级别设置的 trackingMode =&#34;无&#34; 。如果仅更改此属性,则在调用“保存”时,该实体将被视为“未更改”。

并发检查在实体级别完成,而不是在属性级别完成。因此,如果您不希望进行并发检查(在保存时比较Rowversion自动设置的加载和保存之间保存了其他实体),则实体级别的相关设置是属性 concurrencyMode 默认值为&#34;乐观&#34; ,以便在加载和保存之间进行更改时引发ConcurrencyException。您可以将其设置为无(正如您所做),没有例外,并允许对此实体进行任何保存。 如果您需要对给定属性进行非常具体的管理而不需要其他属性,而在实体级别使用默认并发,则可以使用例如:

  • 此属性上的特定OnAfterSet规则(请参阅Property EventRules)以设置&#34;脏&#34;仅为此属性标记

  • 和一个OnBeforeSave方法,只有在此属性发生更改时才调用仅具有Rowversion的重新加载(请参阅Concurrency Modes

并完成:&#34; _lastSave&#34;提及。如果您正在参考自动跟踪列&#34; [_ trackLastWriteTime / User]&#34;在数据库中。它也是一个实体级功能。默认情况下,它在DB中更新时写入。它与给定的财产无关。如果您不希望在此实体的数据库中包含这些信息,则可以更改实体级别跟踪模式属性,该属性默认设置为时间/用户和/ CreationState(&#34; [ _tracCreationTime / User]&#34;)为无。