コード例 #1
0
ファイル: Company.cs プロジェクト: kennethmyhra/khufu
 public virtual void AddEmployee(Employee employee)
 {
     employee.Company = this;
     Employees.Add(employee);
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: kennethmyhra/khufu
        static void Main(string[] args)
        {
            ISessionFactory sessionFactory = CreateSessionFactory();
            using (ISession session = sessionFactory.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    var khufu = new Company
                    {
                        OrganizationNumber = "123456789",
                        Name = "Khufu"
                    };

                    var okado = new Company
                    {
                        OrganizationNumber = "234567890",
                        Name = "Okado"
                    };

                    var kenneth = new Employee
                    {
                        BirthNumber = "16027512345",
                        Firstname = "Kenneth",
                        Surname = "Myhra"
                    };
                    var paras = new Employee
                    {
                        BirthNumber = "01017312345",
                        Firstname = "Paras",
                        Surname = "Kafley"
                    };

                    var christian = new Employee
                    {
                        BirthNumber = "01057523456",
                        Firstname = "Christian",
                        Surname = "Bogstad"
                    };

                    var padraic = new Employee
                    {
                        BirthNumber = "01017634567",
                        Firstname = "Padraic",
                        Surname = "Woods"
                    };

                    var axel = new Employee
                    {
                        BirthNumber = "14047512335",
                        Firstname = "Axel",
                        Surname = "Haugan"
                    };

                    AddEmployeesToCompany(khufu, kenneth, paras, axel, christian, padraic);

                    AddEmployeesToCompany(okado, padraic, christian);

                    session.SaveOrUpdate(khufu);

                    session.SaveOrUpdate(okado);

                    transaction.Commit();
                }
                using (session.BeginTransaction())
                {
                    var companies = session.CreateCriteria<Company>()
                        .List<Company>();
                    foreach (var company in companies)
                    {
                        WriteCompanyPretty(company);
                    }
                }
            }
            Console.ReadKey(true);
        }