Hi
Thanks for the help. That all worked fine. My code now looks like the following
// Create an Entity Class based on the Table Name
public CommonEntityBase CreateEntity(String Table)
{
thisTable = char.ToUpper(Table[0]) + Table.Substring(1); //Make the first character uppercase
String Name = String.Format("MicronetDAL.EntityClasses.{0}Entity", thisTable);
Assembly a = Assembly.LoadFrom(".\\MicronetDAL.dll");
thisEntityType = a.GetType(Name);
TableEntity = (CommonEntityBase)Activator.CreateInstance(thisEntityType);
return(TableEntity);
}
// Create a Entity Collection based on the Table name
public EntityCollection GetEntityCollection()
{
object e;
String Name = String.Format("MicronetDAL.FactoryClasses.{0}EntityFactory", thisTable);
Assembly a = Assembly.LoadFrom(".\\MicronetDAL.dll");
Type t = a.GetType(Name);
e = (object)Activator.CreateInstance(t);
return (new EntityCollection((IEntityFactory2)e));
}
String ConvertFieldName(String f)
{
String ret = char.ToUpper(f[0]) + f.Substring(1);
return(ret);
}
bool FetchEntityCollection(DataAccessAdapter da, EntityCollection thisCollection, IRelationPredicateBucket filter, int max)
{
try
{
da.FetchEntityCollection(thisCollection, filter, max);
if (thisCollection.Count == 0)
{
Diagnostic.ErrorCode = Error_Code.INOT_ERR;
Diagnostic.LastError = "";
return (false);
}
return (true);
}
catch (Exception ex)
{
Diagnostic.CatchError(ex, null,null);
return (false);
}
}
public bool SelectRecord(String table, sqlSelectParam[] SelectArray)
{
bool ret = true;
DataAccessAdapter da = new DataAccessAdapter();
CommonEntityBase = CreateEntity(table);
EntityCollection thisCollection = GetEntityCollection();
try
{
IRelationPredicateBucket filter = new RelationPredicateBucket();
for (int i = 0; i < SelectArray.Length; i++)
{
FieldCompareValuePredicate predicateToAdd = null;
IEntityField2 f = TableEntity.Fields[ConvertFieldName(SelectArray[i].FieldName)];
predicateToAdd = new FieldCompareValuePredicate(f, null, ComparisonOperator.Equal, SelectArray[i].value);
if (predicateToAdd != null)
{
if (i == 0)
filter.PredicateExpression.Add(predicateToAdd);
else
filter.PredicateExpression.AddWithAnd(predicateToAdd);
}
}
ret = this.FetchEntityCollection(da,thisCollection, filter, 0);
}
catch (Exception ex)
{
ret = false;
Diagnostic.CatchError(ex, null, thisTable);
}
return (ret);
}