コード例 #1
0
ファイル: Test.cs プロジェクト: smartinz/randomhacking
        public void TestCase()
        {
            ExpenseType t = new ExpenseType();
            t.Description = "Auto";

            Expense e = new Expense();
            e.Date = new DateTime(2009, 1, 18);
            e.Description = "description";
            e.Type = t;
            e.Amount = 100;

            using(var session = _sessionFactory.OpenSession())
                using(session.BeginTransaction())
            {
                session.Save(t);
                session.Save(e);
                session.Transaction.Commit();
            }
            int id = e.Id;
            e = _sessionFactory.OpenSession().Get<Expense>(id);

            Assert.AreEqual(id, e.Id);
            Assert.AreEqual("description", e.Description);
            Assert.AreEqual("Auto", e.Type.Description);
            Assert.AreEqual(100, e.Amount);
        }
コード例 #2
0
ファイル: Main.cs プロジェクト: smartinz/randomhacking
        public static void Main(string[] args)
        {
            ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory();

            Expense e = new Expense();

            Provider p = new Provider(sessionFactory.OpenSession());
            e = p.GetExpenseById(1);

            e.Date = new DateTime(2009, 1, 18);
            e.Description = "description";
            e.Amount = 100;
            //e.ExpenseTypeId = 1;

            using(var session = sessionFactory.OpenSession())
                using(session.BeginTransaction())
            {
                session.Save(e);
                session.Transaction.Commit();
            }

            //			Expense e = new Expense();
            //
            //
            //
            //			Provider p = new Provider();
            //			e = p.GetExpenseById(1);
            //
            //			Console.Write(e.Id);
            //			Console.Write(e.Description);
            //			Console.Write(e.Amount);
            //
            //			Mono.Data.Sqlite.SqliteConnection conn = new Mono.Data.Sqlite.SqliteConnection("Data Source=database.sqlite3");
            //			Mono.Data.Sqlite.SqliteCommand cmd = new Mono.Data.Sqlite.SqliteCommand("select * from expenses", conn);
            //			conn.Open();
            //			Mono.Data.Sqlite.SqliteDataReader rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            //			string s = "";
            //			while(rdr.Read())
            //			{
            //				s+=rdr.ToString();
            //			}
            //
            //
            //

            Application.Init ();
            MainWindow win = new MainWindow ();
            win.Show ();
            Application.Run ();
        }