public List <T> GetByCriteria <T>(string criteria) { Type entity = typeof(T); List <T> list = new List <T>(); string tableName = AttributeInfo.GetTableName(entity); try { using (var em = EntityManagerFactory.CreateInstance(dataSource)) { string sql = "SELECT * FROM " + tableName + " WHERE " + criteria; list = em.ExecuteList <T>(sql); } } catch (Exception ex) { throw new Exception(ex.ToString()); } return(list); }
public T GetById <T, P>(P id) { Type entity = typeof(T); T obj = default(T); string tableName = AttributeInfo.GetTableName(entity); try { using (var em = EntityManagerFactory.CreateInstance(dataSource)) { string sql = "SELECT * FROM " + tableName + " WHERE " + GetQueryClause(em.DataSource, entity, id); obj = em.ExecuteObject <T>(sql); } } catch (Exception ex) { throw new Exception(ex.ToString()); } return(obj); }