Hi All,
Using 2.6 (sorry
). I have created a custom entity factory with the intention of creating an entity collection of sub-type, like this:
FormInstanceCollection formInstances = new FormInstanceCollection(new ExtendedFormInstanceFactory());
However, when I try and access one of the items in the collection, it's type is still of the super-type ''FormInstanceEntity", so I get a cast exception. I can't think what I might be missing...
ExtendedFormInstanceEntity DOES inherit from FormInstanceEntity
Here's some code:
Custom Factory:
[Serializable]
public class ExtendedFormInstanceFactory : EntityFactoryBase
{
/// <summary>
/// Initializes a new instance of the <see cref="ExtendedFormInstanceFactory"/> class.
/// </summary>
public ExtendedFormInstanceFactory()
: base("FormInstanceEntity", EntityType.FormInstanceEntity)
{
}
/// <summary>
/// Creates this instance.
/// </summary>
/// <returns></returns>
public override SD.LLBLGen.Pro.ORMSupportClasses.IEntity Create()
{
IEntity extended = new ExtendedFormInstanceEntity();
return extended;
}
/// <summary>
/// Creates the specified fields.
/// </summary>
/// <param name="fields">The fields.</param>
/// <returns></returns>
public override IEntity Create(IEntityFields fields)
{
IEntity extended = new ExtendedFormInstanceEntity();
extended.Fields = fields;
return extended;
}
}
Fetching the collection:
PredicateExpression filter = new PredicateExpression();
filter.Add(FormInstanceFields.ApplicationId == appId);
filter.AddWithAnd(FormInstanceFields.PageId == pageId);
filter.AddWithAnd(FormInstanceFields.Locale == locale);
filter.AddWithAnd(FormInstanceFields.RecordTypeId == WorkflowRecordType.Master);
FormInstanceCollection formInstances = new FormInstanceCollection(new ExtendedFormInstanceFactory());
formInstances.GetMulti(filter);
if (formInstances.Count > 0)
return (ExtendedFormInstanceEntity)formInstances[0]; //<-- Cast exception occurs here!
return new ExtendedFormInstanceEntity();
The only other thing I can think of is that the "FormInstanceEntity" is part of a TargetPerEntity inheritance hieracrchy, should that make any difference?
Thanks,
CM.