I have an entity that I'm using to fetch a typedlist. I'm trying to programmatically add a relationship and a column. I've added the relationship file, but I can't figure out how to add the column (fields).
Essentially I'm looking for something like this.
Entity is IEntity2;
field is IEntityField2;
Entity.Fields.Add(field)
But that fails. So I found the .Expand method off of EntityFields2, but it only takes an int, and I couldn't figure out how to actually add the field to the array, because it's hidden, so I wrote this overloaded method.
/// <summary>
/// Expands this entity fields object by 1, and appending field to this object.
/// </summary>
/// <param name="field">field to append to this fieldsobject</param>
/// <remarks>Use with care. Empty cells can cause the DQE's to produce undefined results. Use this routine to append fields to a
/// Typed list in code for example. </remarks>
public void Expand(IEntityField2 field)
{
IEntityField2[] newFieldsInstance = new EntityField2[_entityFields.Length + 1];
_entityFields.CopyTo(newFieldsInstance, 0);
newFieldsInstance[newFieldsInstance.Length] = field;
_entityFields = newFieldsInstance;
}
Which works great. So I thought I was home free.
My plan was to ...
Entity.Fields.Expand(field);
But that fails becuase Entity.Fields is of type IEntityFields2, not IEntityField2 (see the field vs. fields) so again, i'm stuck.
In a perfect world, the CTOR of ResultsetFields would take an IEntityFields2, or IEntityFieldCore[] object.
I'm obviously missing something.
So the typedlist should return all the columns of Entity + 1, through the relationship. I know the relation is working because I used SQL Profiler, and I can see the correct T-SQL getting to the Server. Now to just add that extra field definition.
Thanks for your help.