Training 1
Training 1
Training 1
• Eager loading is the process whereby a query for one type of entity also
loads related entities as part of the query.
• So that we don't need to execute a separate query for related entities.
• Eager loading is achieved using the Include() method.
• It gets all the students from the database along with its standards using the
Include() method.
LINQ QUERY SYNTAX
•We can also use the LINQ lambda expression as a parameter in the Include
method.
•take a reference of System.Data.Entity namespace and use the lambda
expression
USE LAMBDA EXPRESSION
using System;
using System.Data.Entity;
class Program
{ static void Main(string[] args)
{
using (var ctx = new SchoolDBEntities())
{
var stud1=ctx.Students.Include(s => s.Standard)
.Where(s=>s.StudentName=="Bill")
.FirstOrDefault<Student>();
}
}
}
LOAD MULTIPLE ENTITIES
using (var ctx = new SchoolDBEntities())
{
var stud1=ctx.Students.Include(s => s.Standard.Teachers)
.Where(s => s.StudentName ==
"Bill") .FirstOrDefault<Student>();
}
FIELDS
• A field is a variable that is a member of a class and can hold data of the
class. For example:
public class Student
{
string name;
int age = 10;
}
PROPERTIES
• Provide access to a class attribute (a field). Useful for exposing fields in
components.
• A property is declared like a field, but with a get/set block added.
public class Student
{
public string FirstName
{ get;
set;
}
}
METHODS
• Many developers need access to the same class, then having the class in
multiple files can be beneficial.
• The partial keywords allow a class to span multiple source files.
Eg.
public partial class partialclassDemo
{
}
STATIC CLASSES
• A static class is declared using the "static" keyword.
• If the class is declared as static then the compiler never creates an instance of the class.
• All the member fields, properties and functions must be declared as static and they are accessed by
the class name directly not by a class instance object.
public static class staticDemo
{
public static void Add(int a, int b)
{
return a+b;
}
}
• //function calling directly
staticDemo.Add();
ABSTRACT CLASSES
• using System.Linq.Expressions;
• using System.Linq;
• List<int> numbers = new List<int>{11,37,52};
• List<int> oddNumbers = numbers.where(n => n % 2 == 1).ToList();
var keyword:
var a=10;
QUERY EXPRESSION(LINQ QUERIES)