Entity Graph means the relation between the entities. The type of relation may be anyone.
That means One to One, One to Many..etc
Example
Employee relation with the Departments is an example for Entity graph.In Disconnected Scenario, add Dbset.Add() method in order to attach the entity graph to the context.
The following code will add Employee Entity Graph in the disconnected scenario.
Example
[csharp]
//Create Employee in disconnected mode
Employee newEmployee = new Employee () { Employee Name = "New Single Employee " };
//Assign new standard to Employee entity
newEmployee .Standard = new Standard() { StandardName = "New Standard" };
//add new Department with new Department into Employee.departments
newEmployee.Departments.Add(new Department() { DepartmentName = "New Department for single Employee", Department= new Department() { EmployeeName = "New Department" } });
using (var con= new EmployeeDBEntities())
{
con.Employee.Add(newEmployee);
con.SaveChanges();
Console.WriteLine("New Employee Entity has been added with new EmployeeId= " + newEmployee.EmployeeID.ToString());
Console.WriteLine("New Standard Entity has been added with new StandardId= " + newEmployee.StandardId.ToString());
Console.WriteLine("New Department Entity has been added with newDepartmentId= " + newStudent.Departments.ElementAt(0).DepartmentId.ToString());
Console.WriteLine("New DepartmentEntity has been added with new DepartmentId= " + newEmployee.Departments.ElementAt(0).DepartmentId.ToString());
}
[/csharp]