Determine if a column is present in entity dynamically

Posts   
 
    
toluca70
User
Posts: 1
Joined: 13-Nov-2009
# Posted on: 13-Nov-2009 17:53:01   

v2.6

I'm testing for the presence of a column using FieldInfoProviderSingleton on an unknown entity.


IEntityCollection collection = ....
var info = FieldInfoProviderSingleton.GetInstance().GetFieldIndexes(collection.EntityFactoryToUse.ForEntityName);
if (info.ContainsKey("Status"))
{
  IEntityField status = EntityFieldFactory.Create(collection.EntityFactoryToUse.ForEntityName, "Status");
}

The problem is when I attempt to move the project into it's own dll. The FieldInfoProviderSingleton is sealed internal. Is there a more appropriate way to access this information?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Nov-2009 21:15:48   

I would do something like this:

string fieldName = "Status";
IEntityCollection coll = ...

// found
if (coll.EntityFactoryToUse.CreateFields().GetAsEntityFieldCoreArray().Count(x => x.Name == fieldName) > 0)
{
    IEntityField theField = EntityFieldFactory.Create(coll.EntityFactoryToUse.ForEntityName, fieldName);
}

// not found
else
{
    ...
}
David Elizondo | LLBLGen Support Team