示例#1
0
文件: Tutorial.cs 项目: ekicyou/pasta
        /// <summary>
        /// How to insert a complex object in NeoDatis Database
        /// </summary>
        public void Step2()
        {

            // Create instance
            Sport volleyball = new Sport("volley-ball");

            // Create 4 players
            Player player1 = new Player("olivier", new DateTime(), volleyball);
            Player player2 = new Player("pierre", new DateTime(), volleyball);
            Player player3 = new Player("elohim", new DateTime(), volleyball);
            Player player4 = new Player("minh", new DateTime(), volleyball);

            // Create two teams
            Team team1 = new Team("Paris");
            Team team2 = new Team("Montpellier");

            // Set players for team1
            team1.AddPlayer(player1);
            team1.AddPlayer(player2);

            // Set players for team2
            team2.AddPlayer(player3);
            team2.AddPlayer(player4);

            // Then create a volley ball game for the two teams
            Game game = new Game(new DateTime(), volleyball, team1, team2);

            ODB odb = null;

            try
            {
                // Open the database
                odb = ODBFactory.Open(ODB_NAME);

                // Store the object
                odb.Store(game);
            }
            finally
            {
                if (odb != null)
                {
                    // Close the database
                    odb.Close();
                }
            }
        }
示例#2
0
文件: Team.cs 项目: ekicyou/pasta
 public void AddPlayer(Player player)
 {
     players.Add(player);
 }
示例#3
0
文件: Tutorial.cs 项目: ekicyou/pasta
    /// <summary>
    /// How to delete an object using OID
    /// </summary>
	public void Step14()  {
		ODB odb = null;

		try {
			// Open the database
			odb = ODBFactory.Open(ODB_NAME);

			Sport tennis = odb.GetObjects<Sport>(new CriteriaQuery(typeof(Sport), Where.Equal("name", "Tennis"))).GetFirst();
			// Firts re-create Agassi player - it has been deleted in step 13
			Player agassi = new Player("Andr\u00E9 Agassi", new DateTime(), tennis);
			odb.Store(agassi);
			odb.Commit();

			IQuery query = new CriteriaQuery(typeof(Player), Where.Like("name", "%Agassi"));

			Objects<Player> players = odb.GetObjects<Player>(query);

			// Gets the first player (there is only one!)
			agassi = players.GetFirst();
			OID agassiId = odb.GetObjectId(agassi);

			odb.DeleteObjectWithId(agassiId);

			odb.Close();

			odb = ODBFactory.Open(ODB_NAME);
			// Now query the databas eto check the change
			players = odb.GetObjects<Player>();

			Console.WriteLine("\nStep 14 : Deleting players");

			int i = 1;
			// display each object
			while (players.HasNext()) {
				Console.WriteLine((i++) + "\t: " + players.Next());
			}

		} finally {
			if (odb != null) {
				// Close the database
				odb.Close();
			}
		}
	}
示例#4
0
文件: Tutorial.cs 项目: ekicyou/pasta
    /// <summary>
    /// How to retrieve objects using Criteria queries traversing relations
    /// </summary>
    public void Step4()  {

		ODB odb = null;

		try {
			// Open the database
			odb = ODBFactory.Open(ODB_NAME);
			// Let's insert a tennis player
			Player agassi = new Player("Andr\u00E9 Agassi", new DateTime(), new Sport("Tennis"));
			odb.Store(agassi);

			IQuery query = new CriteriaQuery(typeof(Player), Where.Equal("favoriteSport.name", "volley-ball"));

			Objects<Player> players = odb.GetObjects<Player>(query);

			Console.WriteLine("\nStep 4 : Players of Voller-ball");

			int i = 1;
			// display each object
			while (players.HasNext()) {
				Console.WriteLine((i++) + "\t: " + players.Next());
			}
		} finally {
			if (odb != null) {
				// Close the database
				odb.Close();
			}
		}
	}