Access BCS Data via C#

The below code snippet allows for access BCS data via C#

SPFarm farm = SPFarm.Local;
SPServiceProxyCollection spc = farm.ServiceProxies;
BdcServiceApplicationProxy sap = (BdcServiceApplicationProxy)(
                (from sp in spc 
                 where sp.TypeName.Equals("Business Data Connectivity Service")
                 select sp).First().ApplicationProxies.First());
DatabaseBackedMetadataCatalog catalog = sap.GetDatabaseBackedMetadataCatalog();

 IEntity ect = catalog.GetEntity("WPI.SharePoint.ITPMO.Data.BCS.Planview.ProjectData_Model", "ProjectDataEntity");
ILobSystem lob = ect.GetLobSystem();
ILobSystemInstance lobi = lob.GetLobSystemInstances()["ProjectData_Model"];
IFilterCollection filter = ect.GetDefaultFinderFilters();
IEntityInstanceEnumerator ects = ect.FindFiltered(filter, lobi);
while (ects.MoveNext())
{
Console.WriteLine(ects.Current["ProjectName"].ToString());
}