Join Query using Entity FrameWork

Posted in C#, LINQ, MVCTagged ,

In this article i am explaining how to use JOIN method in Entity Framework. Below is very simple and easy example. var query = db.Employee // source .Join(db.Salary, // target c => c.EmployeeID, // FK cm => cm.EmployeeID, // PK (em, sal) => new { Employee = em, Salary = sal }) // project result….

How to get top 10 records in linq

In this article i am explaining how to get top 10 records in LINQ. below is very simple and easy example. var top10 = (from u in db.Users orderby u.UserId descending select u).Take(10); Note: If you take method then must be use order by clause.  

Difference between firstordefault and singleordefault

Both are the element operators and they are used to select a single element from a sequence. But there is a minor difference between them. SingleOrDefault() operator would throw an exception if more than one elements are satisfied the condition where as FirstOrDefault() will not throw any exception for the same Single() – There is….

Join Query using Entity FrameWork

I am explaining how to use join in entity framework. Example: var data= (from emp in dbContext.Employee join sal in dbContext.Salary on emp.EmployeeID equals sal.EmployeeID select new { EmployeeID= emp.EmployeeID, Name= emp.Name, Salary= sal.Salary }).ToList();