コード例 #1
0
ファイル: Main.cs プロジェクト: hellboy81/ormsimple
        public static void Main(string[] args)
        {
            //Set one before use (i.e. in a static constructor).
            Config.DialectProvider = new FirebirdDialectProvider();

            Config.DialectProvider.ToExistStatement( typeof(Company),
                                                    new Company(){Id=100}, "");

            //using (FirebirdSql.Data.FirebirdClient.FbConnection db =
            //       (FirebirdSql.Data.FirebirdClient.FbConnection)
            //       "User=SYSDBA;Password=masterkey;Database=employee.fdb;DataSource=localhost;Dialect=3;charset=ISO8859_1;".OpenDbConnection())
            //using (FirebirdSql.Data.FirebirdClient.FbCommand dbConn = db.CreateCommand())
            using (IDbConnection db =
                   "User=SYSDBA;Password=masterkey;Database=employee.fdb;DataSource=localhost;Dialect=3;charset=ISO8859_1;".OpenDbConnection())
            using ( IDbCommand dbConn = db.CreateCommand())
            {
                try{

                    Console.WriteLine( dbConn.HasChildren<Company>( new Company(){Id=100} ) );

                    Console.WriteLine(dbConn.HasChildren<Company>( new Company(){Id=5} )) ;

                    Console.WriteLine( dbConn.Exists<Company>( "Id='{0}'",5 ) );

                    Console.WriteLine(dbConn.Exists<Company>( "Id='{0}'",100 )) ;

                    var rows = dbConn.Select<Company>();
                    Console.WriteLine("Company filas antes de insertar :{0}", rows.Count);
                    /*
                    dbConn.Insert(new Company { Name="Hello, World!"});
                    dbConn.Insert(new Company { Name="One Company", Employees=10,
                        Started= DateTime.Today, TurnOver= 12525,
                        CreatedDate= DateTime.Now});
                    */
                    Company cp = new Company{
                        Name="One More Company", Employees=10,
                        Started= DateTime.Today, TurnOver= 12525,
                        CreatedDate= DateTime.Now
                    };

                    dbConn.Insert( cp);

                    rows = dbConn.Select<Company>();
                    Console.WriteLine("Company filas despues de insertar :{0}", rows.Count);
                    foreach(Company u in rows){
                        Console.WriteLine("{0} -- {1}" , u.Id, u.Name);
                    }
                    Console.WriteLine("----------------------");
                    //rows = dbConn.Select<Company>("ID>='10'"); asi funciona
                    rows = dbConn.Select<Company>("ID>={0} order by ID descending  rows 5", 10);
                    Console.WriteLine(rows.Count);
                    foreach(Company u in rows){
                        Console.WriteLine("{0} -- {1} -- {2} -- {3} -- {4} -- {5} --{6}", u.Id, u.Name,
                                          (u.Employees.HasValue)?u.Employees.Value.ToString():"",
                                           u.Started.HasValue?u.Started.Value.ToString():"",
                                          u.TurnOver.HasValue?u.TurnOver.Value.ToString():"",
                                          u.CreatedDate.HasValue?u.CreatedDate.Value.ToString():"",
                                          u.UpperName
                                          );
                    }

                }

                catch(Exception e){
                    Console.WriteLine(e);
                }

            //Assert.That(rows, Has.Count(1));
            //Assert.That(rows[0].Id, Is.EqualTo(1));
            }
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            //Set one before use (i.e. in a static constructor).
            Config.DialectProvider = new FirebirdDialectProvider();

            Config.DialectProvider.ToExistStatement(typeof(Company),
                                                    new Company()
            {
                Id = 100
            }, "");

            //using (FirebirdSql.Data.FirebirdClient.FbConnection db =
            //       (FirebirdSql.Data.FirebirdClient.FbConnection)
            //       "User=SYSDBA;Password=masterkey;Database=employee.fdb;DataSource=localhost;Dialect=3;charset=ISO8859_1;".OpenDbConnection())
            //using (FirebirdSql.Data.FirebirdClient.FbCommand dbConn = db.CreateCommand())
            using (IDbConnection db =
                       "User=SYSDBA;Password=masterkey;Database=employee.fdb;DataSource=localhost;Dialect=3;charset=ISO8859_1;".OpenDbConnection())
                using (IDbCommand dbConn = db.CreateCommand())
                {
                    try{
                        Console.WriteLine(dbConn.HasChildren <Company>(new Company()
                        {
                            Id = 100
                        }));

                        Console.WriteLine(dbConn.HasChildren <Company>(new Company()
                        {
                            Id = 5
                        }));

                        Console.WriteLine(dbConn.Exists <Company>("Id='{0}'", 5));

                        Console.WriteLine(dbConn.Exists <Company>("Id='{0}'", 100));


                        var rows = dbConn.Select <Company>();
                        Console.WriteLine("Company filas antes de insertar :{0}", rows.Count);

                        /*
                         * dbConn.Insert(new Company { Name="Hello, World!"});
                         * dbConn.Insert(new Company { Name="One Company", Employees=10,
                         *      Started= DateTime.Today, TurnOver= 12525,
                         *      CreatedDate= DateTime.Now});
                         */
                        Company cp = new Company {
                            Name        = "One More Company", Employees = 10,
                            Started     = DateTime.Today, TurnOver = 12525,
                            CreatedDate = DateTime.Now
                        };


                        dbConn.Insert(cp);

                        rows = dbConn.Select <Company>();
                        Console.WriteLine("Company filas despues de insertar :{0}", rows.Count);
                        foreach (Company u in rows)
                        {
                            Console.WriteLine("{0} -- {1}", u.Id, u.Name);
                        }
                        Console.WriteLine("----------------------");
                        //rows = dbConn.Select<Company>("ID>='10'"); asi funciona
                        rows = dbConn.Select <Company>("ID>={0} order by ID descending  rows 5", 10);
                        Console.WriteLine(rows.Count);
                        foreach (Company u in rows)
                        {
                            Console.WriteLine("{0} -- {1} -- {2} -- {3} -- {4} -- {5} --{6}", u.Id, u.Name,
                                              (u.Employees.HasValue)?u.Employees.Value.ToString():"",
                                              u.Started.HasValue?u.Started.Value.ToString():"",
                                              u.TurnOver.HasValue?u.TurnOver.Value.ToString():"",
                                              u.CreatedDate.HasValue?u.CreatedDate.Value.ToString():"",
                                              u.UpperName
                                              );
                        }
                    }

                    catch (Exception e) {
                        Console.WriteLine(e);
                    }

                    //Assert.That(rows, Has.Count(1));
                    //Assert.That(rows[0].Id, Is.EqualTo(1));
                }
        }