keyA と keyB の 2 つのキーを持つエンティティ "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);
}
ご回答有難うございます、
2016 年 8 月 29 日の編集
属性 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);
}