/// <summary> /// Create a new FullTimeEmployee object. /// </summary> /// <param name="employeeId">Initial value of the EmployeeId property.</param> /// <param name="firstName">Initial value of the FirstName property.</param> /// <param name="lastName">Initial value of the LastName property.</param> public static FullTimeEmployee CreateFullTimeEmployee(global::System.Int32 employeeId, global::System.String firstName, global::System.String lastName) { FullTimeEmployee fullTimeEmployee = new FullTimeEmployee(); fullTimeEmployee.EmployeeId = employeeId; fullTimeEmployee.FirstName = firstName; fullTimeEmployee.LastName = lastName; return(fullTimeEmployee); }
static void RunExample() { using (var context = new EFRecipesEntities()) { var fte = new FullTimeEmployee { FirstName = "Jane", LastName = "Doe", Salary = 71500M }; context.Employees.AddObject(fte); fte = new FullTimeEmployee { FirstName = "John", LastName = "Smith", Salary = 62500M }; context.Employees.AddObject(fte); var hourly = new HourlyEmployee { FirstName = "Tom", LastName = "Jones", Wage = 8.75M }; context.Employees.AddObject(hourly); context.SaveChanges(); } using (var context = new EFRecipesEntities()) { Console.WriteLine("--- All Employees ---"); foreach (var emp in context.Employees) { bool fullTime = emp is HourlyEmployee ? false : true; Console.WriteLine("{0} {1} ({2})", emp.FirstName, emp.LastName, fullTime ? "Full Time" : "Hourly"); } Console.WriteLine("--- Full Time ---"); foreach (var fte in context.Employees.OfType <FullTimeEmployee>()) { Console.WriteLine("{0} {1}", fte.FirstName, fte.LastName); } Console.WriteLine("--- Hourly ---"); foreach (var hourly in context.Employees.OfType <HourlyEmployee>()) { Console.WriteLine("{0} {1}", hourly.FirstName, hourly.LastName); } } Console.WriteLine("Press <enter> to continue..."); Console.ReadLine(); }