예제 #1
0
		public void GenericOperations()
		{
			MapTypes();
			//Drop();
			//Create();

			for (int i = 0; i < 0; i++)
			{
				CustomerContact cc = new CustomerContact();
				cc.Firstname = "Fulanito " + i;
				cc.LastName = "De tal " + i;
				cc.BirthDate = DateTime.Now;
				
				cc.Customer = new Customer();
				cc.Customer.LegalName = "Cliente " + i;
				cc.Customer.Email = "Email " + i;
				
				cc.Address1 = new Address();
				cc.Address1.Street = "Calle " + i;
				cc.Address1.Number = "# " + i;
				cc.Address1.Country = new Country();
				cc.Address1.Country.Name = "Pais " + i;

				cc.Address2 = new Address();
				cc.Address2.Street = "2 Calle " + i;
				cc.Address2.Number = "2 # " + i;
				cc.Address2.Country = cc.Address1.Country;

				DataBase.Table<int, Country>().Add(0, cc.Address1.Country);
				DataBase.Table<int, Address>().Add(0, cc.Address1);
				DataBase.Table<int, Address>().Add(0, cc.Address2);
				DataBase.Table<int, Customer>().Add(0, cc.Customer);
				DataBase.Table<int, CustomerContact>().Add(0, cc);
			}

			Select<CustomerContact> select = new Select<CustomerContact>();
			select.AddMembers
			(
				c => c.Id, 
				c => c.BirthDate, 
				c => c.Customer.LegalName, 
				c=> c.Address1.Street, 
				c=> c.Address1.Country.Name,
				c=> c.Address2.Street,
				c=> c.Address2.Country.Name
			);

			var dtype = DataType<CustomerContact>.GetMap();
			select.Where.Add(new Filters.ValueCompareFilter()
			{
				Member = dtype[x => x.Id],
				ValueToCompare = 3,
				Operator = Data.CompareOperator.LessThanEqual,
			});
			
			select.OrderBy.Add(new Operations.OrderBy() { Member = dtype[x => x.Id], Direction = Data.SortDirection.Descending });

			var result = DataBase.Select<CustomerContact>(select).ToList();

			//Drop();
		}
예제 #2
0
		public void ComplexSelect()
		{
			MapTypes();
			Create();

			for (int i = 0; i < 20; i++)
			{
				CustomerContact contact = new CustomerContact();

				contact.Customer = new Customer();
				contact.Customer.LegalName = "Empresa " + i;
				contact.Customer.Phone = i.ToString();
				contact.Customer.Email = "*****@*****.**" + i;
				//DataBase.Table<int, Customer>().Add(new KeyValuePair<int, Customer>(0, contact.Customer));
				DataBase.Insert(contact.Customer);

				contact.Firstname = "Argentina " + i;
				contact.LastName = "Chichona";
				contact.BirthDate = new DateTime(1980, 1, 1).AddDays(i);
				//DataBase.Table<int, CustomerContact>().Add(new KeyValuePair<int, CustomerContact>(0, contact));
				DataBase.Insert(contact);

			}


			Select<CustomerContact> select = new Select<CustomerContact>();
			select.AddMembers
			(
				c => c.Firstname,
				c => c.LastName,
				c => c.BirthDate,
				c => c.Customer.LegalName,
				c => c.Customer.Phone,
				c => c.Customer.Email
			);

			select.Limit = new SelectLimit(0, 10);

			foreach (CustomerContact e in DataBase.Select(select))
			{
				Console.WriteLine(e.Firstname + " " + e.Customer.LegalName);
			}

			Drop();
		}