コード例 #1
0
 private static void TestEmployee()
 {
     using var context = new EmployeeContext();
     context.Employees.Add(FullTimeEmployee.Create("Jane", "Doe", 71500M));
     context.Employees.Add(FullTimeEmployee.Create("John", "Smith", 62500M));
     context.Employees.Add(HourlyEmployee.Create("Tom", "Jones", 8.75M));
     context.SaveChanges();
     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);
     }
 }
コード例 #2
0
 public static void Scenariu5()
 {
     using (var context = new Scenariu5())
     {
         var fte = new FullTimeEmployee
         {
             FirstName = "Jane",
             LastName  =
                 "Doe",
             Salary = 71500M
         };
         context.Employees.Add(fte);
         fte = new FullTimeEmployee
         {
             FirstName = "John",
             LastName  = "Smith",
             Salary    = 62500M
         };
         context.Employees.Add(fte);
         var hourly = new HourlyEmployee
         {
             FirstName = "Tom",
             LastName  =
                 "Jones",
             Wage = 8.75M
         };
         context.Employees.Add(hourly);
         context.SaveChanges();
     }
     using (var context = new Scenariu5())
     {
         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);
         }
     }
 }
コード例 #3
0
ファイル: ScenarioFive.cs プロジェクト: razvan-maftei/Lab5
 public void Add()
 {
     using (var context = new EmployeeContext())
     {
         var fte = new FullTimeEmployee {
             FirstName = "Jane", LastName = "Doe", Salary = 71500M
         };
         context.Employees.Add(fte);
         fte = new FullTimeEmployee {
             FirstName = "John", LastName = "Smith", Salary = 62500M
         };
         context.Employees.Add(fte);
         var hourly = new HourlyEmployee {
             FirstName = "Tom", LastName = "Jones", Wage = 8.75M
         };
         context.Employees.Add(hourly);
         context.SaveChanges();
     }
 }