I see now. Ok, from your previous posts I know you are using Adapter.
This is not a straight forward task, however it could be done. The problem is that the DataAdapterClass and PersistenceInfoProvider don't know anything about your specific entity classes. The most you can do over there is to obtain the table name for a passes IEntity2. Example:
public partial class DataAccessAdapter
{
public string GetTableName(string entityName)
{
return this.GetFieldPersistenceInfos(entityName)[0].SourceObjectName;
}
}
However, with that code you can create a routine in your business code that finds the entity based on your table name:
public IEntity2 GetEntityFromTableName(string tableNameToFind)
{
IEntity2 toReturn;
using (var adapter = new DataAccessAdapter())
{
var entityAsString = (from e in Enum.GetNames(typeof(EntityType))
let tableName = adapter.GetTableName(e)
where tableName == tableNameToFind
select e).FirstOrDefault();
toReturn = FactoryClasses.GeneralEntityFactory.Create(
(EntityType)Enum.Parse(typeof(EntityType), entityAsString));
}
return toReturn;
}
.. and then use it:
[TestMethod]
public void GetEntityFromTableName()
{
IEntity2 entity = GetEntityFromTableName("Customers");
Assert.IsTrue(entity is CustomerEntity);
}
Hope helpful.