序列化属性
Serializing properties
我在 CF 文档、常见问题解答、博客和 SO 条目中到处搜索,但仍然无法理解为什么使用此模型:
<cf:project defaultNamespace="Humanisme" xmlns:cf="http://www.softfluent.com/codefluent/2005/1" xmlns:cfx="http://www.softfluent.com/codefluent/modeler/2008/1" xmlns:cfom="http://www.softfluent.com/codefluent/producers.model/2005/1" xmlns:cfps="http://www.softfluent.com/codefluent/producers.sqlserver/2005/1" xmlns:cfsm="http://www.softfluent.com/codefluent/producers.servicemodel/2007/1" defaultKeyPropertyTypeName="int" defaultMaxLength="240" persistencePropertyNameFormat="{1}" createDefaultMethodForms="true" createDefaultApplication="false" createDefaultHints="false">
<cf:import path="Default.Surface.cfp" />
<cf:producer name="Business Object Model (BOM)" typeName="CodeFluent.Producers.CodeDom.CodeDomProducer, CodeFluent.Producers.CodeDom">
<cf:configuration compileWithVisualStudio="true" compile="false" codeDomProviderTypeName="CSharp" targetDirectory="..\Humanisme.classes" produceWebMembershipProvider="false" produceWebProfileProvider="false" produceWebBasicAuthenticationModule="false" cfx:targetProject="..\Humanisme.classes\Humanisme.classes.csproj" cfx:targetProjectLayout="Update">
<subProducer typeName="CodeFluent.Producers.ServiceModel.ServiceProducer, CodeFluent.Producers.ServiceModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1bb6d7cccf1045ec" compileWithVisualStudio="true" compile="false" codeDomProviderTypeName="CSharp" targetDirectory="..\Humanisme.webApi" silverlightTargetVersion="Unspecified" dataAnnotationsProductionModes="NoAnnotations, All" jsonOptions="EnableJson" outputName="HumanismeService" cfx:targetProject="..\Humanisme.webApi\Humanisme.webApi.csproj" cfx:targetProjectLayout="Update" produceProxy="False" />
</cf:configuration>
</cf:producer>
(....)
<cf:entity name="EtapaVital" namespace="Humanisme" categoryPath="/Humanisme">
<cf:property name="Id" key="true" />
<cf:property name="Nom" />
<cf:property name="Idioma" typeName="{0}.EtapaVitalIdiomaCollection" relationPropertyName="Etapa" />
<cf:property name="Documents" typeName="{0}.DocumentCollection" relationPropertyName="EtapaVital" />
</cf:entity>
呈现这些序列化属性:
- RowVersion 和 EntityState 获取序列化属性。
EntityDisplayName 没有。
[System.Runtime.Serialization.DataMemberAttribute(Order=2147483647)]
private CodeFluent.Runtime.CodeFluentEntityState _entityState;
public EtapaVital()
[System.Runtime.Serialization.DataMemberAttribute()]
public virtual string EntityKey
{
get
{
return this.Id.ToString();
}
set
{
this.Id = ((int)(ConvertUtilities.ChangeType(value, typeof(int), -1)));
}
}
public virtual string EntityDisplayName
{
get
{
return this.Nom;
}
}
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
[System.ComponentModel.DataObjectFieldAttribute(false, true)]
[System.ComponentModel.TypeConverterAttribute(typeof(CodeFluent.Runtime.Design.ByteArrayConverter))]
[System.Runtime.Serialization.DataMemberAttribute()]
public byte[] RowVersion
{
get
{
return this._rowVersion;
}
set
{
if (((value != null)
&& (value.Length == 0)))
{
value = null;
}
this._rowVersion = value;
this.OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("RowVersion"));
}
}
[System.ComponentModel.DefaultValueAttribute(((int)(-1)))]
[System.Xml.Serialization.XmlElementAttribute(IsNullable=false, Type=typeof(int))]
[System.ComponentModel.DataObjectFieldAttribute(true)]
[System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false, Order=100)]
public int Id
{
get
{
return this._id;
}
set
{
if ((System.Collections.Generic.EqualityComparer<int>.Default.Equals(value, this._id) == true))
{
return;
}
int oldKey = this._id;
this._id = value;
try
{
this.OnCollectionKeyChanged(oldKey);
}
catch (System.ArgumentException )
{
this._id = oldKey;
return;
}
this.EntityState = CodeFluent.Runtime.CodeFluentEntityState.Modified;
this.OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("Id"));
}
}
[System.ComponentModel.DefaultValueAttribute(default(string))]
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true, Type=typeof(string))]
[System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false, Order=200)]
public string Nom
{
get
{
return this._nom;
}
set
{
this._nom = value;
this.EntityState = CodeFluent.Runtime.CodeFluentEntityState.Modified;
this.OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("Nom"));
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public Humanisme.EtapaVitalIdiomaCollection Idioma
{
get
{
if ((this._idioma == null))
{
if (((this.Id == -1)
|| (this.EntityState.Equals(CodeFluent.Runtime.CodeFluentEntityState.Created) == true)))
{
this._idioma = new Humanisme.EtapaVitalIdiomaCollection(this);
return this._idioma;
}
this._idioma = Humanisme.EtapaVitalIdiomaCollection.LoadByEtapa(this);
}
return this._idioma;
}
}
[System.Xml.Serialization.XmlIgnoreAttribute()]
public Humanisme.DocumentCollection Documents
{
get
{
if ((this._documents == null))
{
if (((this.Id == -1)
|| (this.EntityState.Equals(CodeFluent.Runtime.CodeFluentEntityState.Created) == true)))
{
this._documents = new Humanisme.DocumentCollection(null, this);
return this._documents;
}
this._documents = Humanisme.DocumentCollection.LoadByEtapaVital(this);
}
return this._documents;
}
}
public virtual CodeFluent.Runtime.CodeFluentEntityState EntityState
{
get
{
return this._entityState;
}
set
{
if ((System.Collections.Generic.EqualityComparer<CodeFluent.Runtime.CodeFluentEntityState>.Default.Equals(value, this.EntityState) == true))
{
return;
}
if (((this._entityState == CodeFluent.Runtime.CodeFluentEntityState.ToBeDeleted)
&& (value == CodeFluent.Runtime.CodeFluentEntityState.Modified)))
{
return;
}
if (((this._entityState == CodeFluent.Runtime.CodeFluentEntityState.Created)
&& (value == CodeFluent.Runtime.CodeFluentEntityState.Modified)))
{
return;
}
this._entityState = value;
this.OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("EntityState"));
}
}
模型表面似乎没有相关的 属性 选项 "Properties" window 而且我无法在cfp 文件。
如果您能给我任何线索或参考,我将非常感激从哪里开始学习导致 类 中这些输出的 CodeFluent 模型选项。
再次感谢,我真的要变成 CodeFluent 爱好者了!
RowVersion
属性 由 CodeFluent Entities 生成,因为您将并发模式设置为 Optimistic
(documentation)。如果您没有此 属性 的最新值,则无法保存该实体 (CodeFluentConcurrencyException
)。所以这个属性需要序列化
EntityDisplayName
用于 UI 目的。它的值是根据一个或多个属性计算的。所以不需要序列化它,因为你可以在客户端计算它。
目前没有属性可以更改这些特定属性的序列化行为。但是,您可以将自定义子生产者写入属性的 add/remove 序列化属性。您会找到一个示例,该示例在属性 (GitHub)
上添加了 Json.NET 个特定属性
这里有一些属性可以改变序列化行为:
serializable
(实体):确定这个实体是否被标记为可序列化
serializeEntityKey
(Entity):判断EntityKey是否必须序列化
serializeTypeName
(实体):判断TypeName是否必须序列化
serializationMode
(属性): documentation
dataMember
或 includeInSerialization
(属性) => 更喜欢使用 serializationMode
serializationOrder
(属性):定义这个属性序列化时的排序顺序
serializationNullable
(属性): 确定序列化时是否可以跳过属性
serializePrivateMember
(属性):判断一个不可序列化的私有字段属性是否可序列化
publicSerializationCallbacks
(项目):判断序列化回调方法是否为public(OnEntityDeserializing
、OnEntityDeserialized
等)
我在 CF 文档、常见问题解答、博客和 SO 条目中到处搜索,但仍然无法理解为什么使用此模型:
<cf:project defaultNamespace="Humanisme" xmlns:cf="http://www.softfluent.com/codefluent/2005/1" xmlns:cfx="http://www.softfluent.com/codefluent/modeler/2008/1" xmlns:cfom="http://www.softfluent.com/codefluent/producers.model/2005/1" xmlns:cfps="http://www.softfluent.com/codefluent/producers.sqlserver/2005/1" xmlns:cfsm="http://www.softfluent.com/codefluent/producers.servicemodel/2007/1" defaultKeyPropertyTypeName="int" defaultMaxLength="240" persistencePropertyNameFormat="{1}" createDefaultMethodForms="true" createDefaultApplication="false" createDefaultHints="false">
<cf:import path="Default.Surface.cfp" />
<cf:producer name="Business Object Model (BOM)" typeName="CodeFluent.Producers.CodeDom.CodeDomProducer, CodeFluent.Producers.CodeDom">
<cf:configuration compileWithVisualStudio="true" compile="false" codeDomProviderTypeName="CSharp" targetDirectory="..\Humanisme.classes" produceWebMembershipProvider="false" produceWebProfileProvider="false" produceWebBasicAuthenticationModule="false" cfx:targetProject="..\Humanisme.classes\Humanisme.classes.csproj" cfx:targetProjectLayout="Update">
<subProducer typeName="CodeFluent.Producers.ServiceModel.ServiceProducer, CodeFluent.Producers.ServiceModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1bb6d7cccf1045ec" compileWithVisualStudio="true" compile="false" codeDomProviderTypeName="CSharp" targetDirectory="..\Humanisme.webApi" silverlightTargetVersion="Unspecified" dataAnnotationsProductionModes="NoAnnotations, All" jsonOptions="EnableJson" outputName="HumanismeService" cfx:targetProject="..\Humanisme.webApi\Humanisme.webApi.csproj" cfx:targetProjectLayout="Update" produceProxy="False" />
</cf:configuration>
</cf:producer>
(....)
<cf:entity name="EtapaVital" namespace="Humanisme" categoryPath="/Humanisme">
<cf:property name="Id" key="true" />
<cf:property name="Nom" />
<cf:property name="Idioma" typeName="{0}.EtapaVitalIdiomaCollection" relationPropertyName="Etapa" />
<cf:property name="Documents" typeName="{0}.DocumentCollection" relationPropertyName="EtapaVital" />
</cf:entity>
呈现这些序列化属性:
- RowVersion 和 EntityState 获取序列化属性。
EntityDisplayName 没有。
[System.Runtime.Serialization.DataMemberAttribute(Order=2147483647)] private CodeFluent.Runtime.CodeFluentEntityState _entityState; public EtapaVital() [System.Runtime.Serialization.DataMemberAttribute()] public virtual string EntityKey { get { return this.Id.ToString(); } set { this.Id = ((int)(ConvertUtilities.ChangeType(value, typeof(int), -1))); } } public virtual string EntityDisplayName { get { return this.Nom; } } [System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] [System.ComponentModel.DataObjectFieldAttribute(false, true)] [System.ComponentModel.TypeConverterAttribute(typeof(CodeFluent.Runtime.Design.ByteArrayConverter))] [System.Runtime.Serialization.DataMemberAttribute()] public byte[] RowVersion { get { return this._rowVersion; } set { if (((value != null) && (value.Length == 0))) { value = null; } this._rowVersion = value; this.OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("RowVersion")); } } [System.ComponentModel.DefaultValueAttribute(((int)(-1)))] [System.Xml.Serialization.XmlElementAttribute(IsNullable=false, Type=typeof(int))] [System.ComponentModel.DataObjectFieldAttribute(true)] [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false, Order=100)] public int Id { get { return this._id; } set { if ((System.Collections.Generic.EqualityComparer<int>.Default.Equals(value, this._id) == true)) { return; } int oldKey = this._id; this._id = value; try { this.OnCollectionKeyChanged(oldKey); } catch (System.ArgumentException ) { this._id = oldKey; return; } this.EntityState = CodeFluent.Runtime.CodeFluentEntityState.Modified; this.OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("Id")); } } [System.ComponentModel.DefaultValueAttribute(default(string))] [System.Xml.Serialization.XmlElementAttribute(IsNullable=true, Type=typeof(string))] [System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false, Order=200)] public string Nom { get { return this._nom; } set { this._nom = value; this.EntityState = CodeFluent.Runtime.CodeFluentEntityState.Modified; this.OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("Nom")); } } [System.Xml.Serialization.XmlIgnoreAttribute()] public Humanisme.EtapaVitalIdiomaCollection Idioma { get { if ((this._idioma == null)) { if (((this.Id == -1) || (this.EntityState.Equals(CodeFluent.Runtime.CodeFluentEntityState.Created) == true))) { this._idioma = new Humanisme.EtapaVitalIdiomaCollection(this); return this._idioma; } this._idioma = Humanisme.EtapaVitalIdiomaCollection.LoadByEtapa(this); } return this._idioma; } } [System.Xml.Serialization.XmlIgnoreAttribute()] public Humanisme.DocumentCollection Documents { get { if ((this._documents == null)) { if (((this.Id == -1) || (this.EntityState.Equals(CodeFluent.Runtime.CodeFluentEntityState.Created) == true))) { this._documents = new Humanisme.DocumentCollection(null, this); return this._documents; } this._documents = Humanisme.DocumentCollection.LoadByEtapaVital(this); } return this._documents; } } public virtual CodeFluent.Runtime.CodeFluentEntityState EntityState { get { return this._entityState; } set { if ((System.Collections.Generic.EqualityComparer<CodeFluent.Runtime.CodeFluentEntityState>.Default.Equals(value, this.EntityState) == true)) { return; } if (((this._entityState == CodeFluent.Runtime.CodeFluentEntityState.ToBeDeleted) && (value == CodeFluent.Runtime.CodeFluentEntityState.Modified))) { return; } if (((this._entityState == CodeFluent.Runtime.CodeFluentEntityState.Created) && (value == CodeFluent.Runtime.CodeFluentEntityState.Modified))) { return; } this._entityState = value; this.OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("EntityState")); } }
模型表面似乎没有相关的 属性 选项 "Properties" window 而且我无法在cfp 文件。
如果您能给我任何线索或参考,我将非常感激从哪里开始学习导致 类 中这些输出的 CodeFluent 模型选项。
再次感谢,我真的要变成 CodeFluent 爱好者了!
RowVersion
属性 由 CodeFluent Entities 生成,因为您将并发模式设置为 Optimistic
(documentation)。如果您没有此 属性 的最新值,则无法保存该实体 (CodeFluentConcurrencyException
)。所以这个属性需要序列化
EntityDisplayName
用于 UI 目的。它的值是根据一个或多个属性计算的。所以不需要序列化它,因为你可以在客户端计算它。
目前没有属性可以更改这些特定属性的序列化行为。但是,您可以将自定义子生产者写入属性的 add/remove 序列化属性。您会找到一个示例,该示例在属性 (GitHub)
上添加了 Json.NET 个特定属性这里有一些属性可以改变序列化行为:
serializable
(实体):确定这个实体是否被标记为可序列化serializeEntityKey
(Entity):判断EntityKey是否必须序列化serializeTypeName
(实体):判断TypeName是否必须序列化serializationMode
(属性): documentationdataMember
或includeInSerialization
(属性) => 更喜欢使用serializationMode
serializationOrder
(属性):定义这个属性序列化时的排序顺序serializationNullable
(属性): 确定序列化时是否可以跳过属性serializePrivateMember
(属性):判断一个不可序列化的私有字段属性是否可序列化publicSerializationCallbacks
(项目):判断序列化回调方法是否为public(OnEntityDeserializing
、OnEntityDeserialized
等)