CodeFluentEntityState 保持不变



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

<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" />

当我设置现有项目的"CostTotalExclVat"时,CodeFluentEntityState保持"不变",因此它不会保存更改。它可能与"跟踪模式"有关。但我不知道正确的设置。我不想要任何并发检查或_lastSave等。我做错了什么?

原因肯定是您在此属性级别设置的trackingMode="none"。如果仅更改此属性,则在调用"保存"时,该实体将被视为"未更改"。

并发检查是在实体级别完成的,而不是在属性级别完成的。因此,如果您不希望并发检查(在加载和保存之间比较保存时自动设置的行版本,在加载和保存之间保存其他内容保存实体),则实体级别的相关设置是属性并发模式默认值"乐观">,以便在加载和保存之间完成更改时引发并发异常。您可以将其设置为"无"(就像您所做的那样)以没有异常并允许对此实体进行任何保存。 如果您需要对给定属性进行非常具体的管理,但不需要其他属性,而在实体级别使用默认并发,则可以使用例如:

此属性
  • 上的特定 OnAfterSet 规则(请参阅属性事件规则),用于仅为此属性设置"脏"标志

  • 以及一个 OnBeforeSave 方法,用于仅使用 Rowversion 调用重新加载,以防此属性发生更改(请参阅并发模式)

最后:提到的"_lastSave"。如果您引用数据库中的自动跟踪列"[_trackLastWriteTime/用户]"。它也是一个实体级别的功能。默认情况下,它是在数据库中有更新时写入的。它与给定的属性无关。如果不希望在数据库中包含此实体的这些信息,则可以更改"实体级别跟踪模式"属性,该属性默认设置为"时间/用户",将"/CreationState"("[_tracCreationTime/用户]")更改为"无"。

相关内容

  • 没有找到相关文章

最新更新