Given an Entity "MultipleKeysEntity" with 2 keys keyA and keyB.
KeyA is of type Enumeration; KeyB is of type guid.
Generated code for Equals method thanks to BOM producer doesn't take keyA in consideration. Is it a normal behavior ?
<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>
Below the generated code
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);
}
Thanks for your answer,
EDIT of 29/08/2016
After setting attribute checkDefaultValue to true, Equals method uses the property as expected. But the first value of the enums is then considered as an "invalid" value.
In particular the method MultipleKeysEntityCollection::baseAdd() prevents me of using value "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;
}
The code of the Equals method is given as below:
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);
}
By default, the enum properties of a composite key are not used for equal comparison. You can instruct the BOM producer to use the property by setting the xml attribute cfom:checkDefaultValue="true"
:
<cf:property name="Id2" cfom:checkDefaultValue="true" />