给定具有 2 个键 keyA 和 keyB 的实体“MultipleKeysEntity”。
KeyA 是枚举类型;KeyB 属于 guid 类型。
由于 BOM 生产者为 Equals 方法生成的代码没有考虑 keyA。这是正常行为吗?
<cf:entity name="MultipleKeysEntity" defaultUsePersistenceDefaultValue="false" baseEqualsOverride="false" setType="List" namespace="Project.Namespace" >
<cf:property name="keyA" persistenceIdentity="false" key="true" typeName="{0}.Enumeration" />
<cf:property name="keyB" key="true" />
<cf:property name="property" typeName="decimal" /></cf:entity>
<cf:enumeration name="Enumeration" namespace="Project.Namespace" >
<cf:enumerationValue name="ONE" />
<cf:enumerationValue name="TWO" /></cf:enumeration>
下面生成的代码
public virtual bool Equals(Project.Namespace.MultipleKeysEntity multipleKeysEntity)
{
if ((multipleKeysEntity == null))
{
return false;
}
if ((this.keyB == CodeFluentPersistence.DefaultGuidValue))
{
return base.Equals(multipleKeysEntity);
}
return (this.keyB.Equals(multipleKeysEntity.keyB) == true);
}
感谢您的回答,
29/08/2016 编辑
将属性 checkDefaultValue 设置为 true 后,Equals 方法按预期使用该属性。但是枚举的第一个值随后被视为“无效”值。
特别是 MultipleKeysEntityCollection::baseAdd() 方法阻止我使用值“ONE”
protected virtual int BaseAdd(WcfServices.Model.Association.MultipleKeysEntity multipleKeysEntity)
{
if ((multipleKeysEntity == null))
{
throw new System.ArgumentNullException("multipleKeysEntity");
}
if (((multipleKeysEntity.keyA == WcfServices.Model.Association.Enumeration.ONE)
|| (multipleKeysEntity.keyB.Equals(CodeFluentPersistence.DefaultGuidValue) == true)))
{
CodeFluent.Runtime.CodeFluentRuntimeException.Throw("invalidEntityKey", "keyA, keyB", "multipleKeysEntity", "WcfServices.Model.Association.MultipleKeysEntity");
}
int localAdd = this.BaseList.Count;
this.BaseList.Add(multipleKeysEntity);
this.OnCollectionChanged(new CodeFluent.Runtime.Utilities.IndexedCollectionChangeEventArgs(System.ComponentModel.CollectionChangeAction.Add, multipleKeysEntity, localAdd));
this.OnListChanged(new System.ComponentModel.ListChangedEventArgs(System.ComponentModel.ListChangedType.ItemAdded, localAdd));
return localAdd;
}
Equals 方法的代码如下:
public virtual bool Equals(WcfServices.Model.Association.MultipleKeysEntity multipleKeysEntity)
{
if ((multipleKeysEntity == null))
{
return false;
}
if (((this.keyA == WcfServices.Model.Association.Enumeration.ONE)
|| (this.keyB == CodeFluentPersistence.DefaultGuidValue)))
{
return base.Equals(multipleKeysEntity);
}
return ((this.keyA.Equals(multipleKeysEntity.keyA) && this.keyB.Equals(multipleKeysEntity.keyB))
== true);
}