public List <Usuarios_Tabla> GetUsuarios(ref string error) { try { using (workspaceEntities bd = new workspaceEntities()) // workspaceEntities -> nombre de conexíón a bd { var query = (from item in bd.Usuarios_Tabla select item).ToList(); return(query); } } catch (Exception e) { error = e.Message; return(null); } }
//insert// Códigos de error virtual public bool Insertar(ref string error, tEntity item) { error = string.Empty; try { using (workspaceEntities ctx = new workspaceEntities()) { ctx.Entry(item).State = EntityState.Added; ctx.SaveChanges(); return(true); } } catch (Exception e) { error = e.Message; return(false); } }
public static bool Truncate(ref string error, string nombreTabla) { error = string.Empty; try { using (workspaceEntities ctx = new workspaceEntities()) { ctx.Database.ExecuteSqlCommand(string.Format("TRUNCATE TABLE {0}", nombreTabla)); ctx.SaveChanges(); return(true); } } catch (Exception e) { error = e.Message; return(false); } }
public Usuarios_Tabla ValidarUsuario(ref string error, string cedula) { try { Usuarios_Tabla resultado = null; using (workspaceEntities bd = new workspaceEntities()) // workspaceEntities -> nombre de conexíón a bd { var query = (from item in bd.Usuarios_Tabla where item.cedula == cedula select item); resultado = query.FirstOrDefault <Usuarios_Tabla>(); } return(resultado); } catch (Exception e) { error = e.Message; return(null); } }
//select lista virtual public List <tEntity> GetAll(ref string error) { error = string.Empty; List <tEntity> emptyCollection = new List <tEntity>(); try { List <tEntity> lstResult = new List <tEntity>(); using (workspaceEntities ctx = new workspaceEntities()) { lstResult = ctx.Set <tEntity>().Select(item => item).ToList(); } return(lstResult); } catch (Exception e) { error = e.Message; return(emptyCollection); } }
// actualizar virtual public bool Actualizar(ref string error, tEntity item) { int result = -1; error = string.Empty; try { using (workspaceEntities ctx = new workspaceEntities()) { // puede insertar registros relacionados (no actualizarlos) ctx.Entry(item).State = EntityState.Modified; result = ctx.SaveChanges(); return(true); } } catch (Exception e) { error = e.Message; return(false); } }