Skip to main content

Posts

Showing posts from October, 2016

Highest salary query in sql server

DECLARE @dtDepartment TABLE ( Id int, Name varchar(100) ) DECLARE @dtEmployee TABLE ( Id int, Name varchar(100), DeptId int ) DECLARE @dtEmpSalary TABLE ( Id int, EmpId int, Salary int ) INSERT INTO @dtDepartment VALUES(1,'.NET') INSERT INTO @dtDepartment VALUES(2,'Java') INSERT INTO @dtEmployee VALUES(1,'Brijesh',1) INSERT INTO @dtEmployee VALUES(2,'Parth',1) INSERT INTO @dtEmployee VALUES(3,'Ruchir 1',1) INSERT INTO @dtEmployee VALUES(4,'Jainik 1',1) INSERT INTO @dtEmployee VALUES(5,'Ruchir',2) INSERT INTO @dtEmployee VALUES(6,'Jainik',2) INSERT INTO @dtEmployee VALUES(7,'Jainik',2) INSERT INTO @dtEmployee VALUES(8,'Jainik',2) INSERT INTO @dtEmpSalary VALUES(1,1,10000) INSERT INTO @dtEmpSalary VALUES(2,2,15000) INSERT INTO @dtEmpSalary VALUES(3,3,12000) INSERT INTO @dtEmpSalary VALUES(4,4,12000) INSERT INTO @dtEmpSalary VALUES(5,5,12000) INSERT INTO @dtEmpSa

CRUD in EF

 public int Create(Users entity)         {             using (var context = new K305DataEntities())             {                 var newEntity = Mapper.Map<User>(entity);                             context.Users.Add(newEntity);                 context.SaveChanges();                 return newEntity.Id;             }         }         public int Update(Users entity)         {             using (var context = new K305DataEntities())             {                 var dbEntity = context.Users.FirstOrDefault(dc => dc.Id == entity.Id);                 if (dbEntity == null) throw new ApplicationException("Entity not found.");                 dbEntity.Name = entity.Name;                 context.SaveChanges();                 return dbEntity.Id;             }                 }         public List<Users> GetAll()         {             using (var context = new K305DataEntities())             {                 return context.Users.Select(