Пример #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 ManualMap()
		{
			DataType<Person> dtype = new DataType<Person>();
			DataType.AllDataTypes.Add(dtype);
			dtype.AddMember(m => m.Id);
			dtype.AddMember(m => m.Firstname);
			
			DataType<CustomerContact> dtype2 = new DataType<CustomerContact>();
			DataType.AllDataTypes.Add(dtype2);
			dtype2.AddMember(m => m.Id);
			dtype2.AddMember(m => m.Customer.Id);
			dtype2.AddMember(m => m.Customer.LegalName);
			dtype2.AddMember(m => m.Customer.Phone);
			DataBase.Create<CustomerContact>();

			for(int i = 0; i < 30; i++)
			{
				CustomerContact cc = new CustomerContact();
				cc.Firstname = "Maria " + i;
				cc.Customer = new Customer();
				cc.Customer.LegalName = "Empresa " + i;
				cc.Customer.Phone= "Telefono " + i;

				DataBase.Table<int, CustomerContact>().Add(0, cc);
			}

			foreach (var cc in DataBase.Table<int, CustomerContact>())
			{
				Console.WriteLine(cc.Value.Firstname + " " + cc.Value.Customer.LegalName);
			}
			
			DataBase.Drop<CustomerContact>();
		}
Пример #3
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));

				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));
			}

			Select<CustomerContact> select = new Select<CustomerContact>();
			
			foreach (var member in select.DataType.DataMembers)
			{
				select.Members.Add(new Operations.SelectMember(member));
			}

			SelectJoin join = new SelectJoin();
			join.JoinType = SelectJoinType.Inner;
			join.Type = typeof(Customer);
			join.On.Add(new Filters.MemberCompareFilter(){ Member = select.DataType["Customer.Id"], MemberToCompare = join.Type["id"], Operator = Data.CompareOperator.Equal });
			select.Joins.Add(join);

			foreach (var member in join.Type.DataMembers.Where(m=> !m.Column.IsPrimaryKey))
			{
				select.Members.Add(new Operations.SelectMember(member));
			}

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

			Drop();
		}
Пример #4
0
		public void BigSelect()
		{
			MapTypes();
			Create();

			for (int i = 0; i < 5000; 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));
				
				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));
			}

			foreach (var e in DataBase.Table<int, CustomerContact>())
			{
				Console.WriteLine(e.Key + " " + e.Value.Firstname);
			}

			Drop();
		}
Пример #5
0
		public void ManualMapWithTables()
		{
			Table personTable = new Table("personTable");
			personTable.Columns.Add(new Column() { IsPrimaryKey = true, Name = "key", DbType = Sql.DbType.Int32 });
			personTable.Columns.Add(new Column() { Name = "name", DbType = Sql.DbType.String });
			personTable.Columns.Add(new Column() { Name = "birth", DbType = Sql.DbType.DateTime });

			DataType<Person> dtype = new DataType<Person>(personTable);
			DataType.AllDataTypes.Add(dtype);
			dtype.AddMember(m => m.Id, personTable["key"]);
			dtype.AddMember(m => m.Firstname, personTable["name"]);
			dtype.AddMember(x => x.BirthDate, personTable["birth"]);

			DataType<CustomerContact> dtype2 = new DataType<CustomerContact>();
			DataType.AllDataTypes.Add(dtype2);
			dtype2.AddMember(m => m.Id);
			dtype2.AddMember(m => m.Customer.Id);
			dtype2.AddMember(m => m.Customer.LegalName);
			dtype2.AddMember(m => m.Customer.Phone);
			DataBase.Create<CustomerContact>();

			for (int i = 0; i < 30; i++)
			{
				CustomerContact cc = new CustomerContact();
				cc.Firstname = "Maria " + i;
				cc.Customer = new Customer();
				cc.Customer.LegalName = "Empresa " + i;
				cc.Customer.Phone = "Telefono " + i;

				DataBase.Table<int, CustomerContact>().Add(0, cc);
			}

			foreach (var cc in DataBase.Table<int, CustomerContact>())
			{
				Console.WriteLine(cc.Value.Firstname + " " + cc.Value.Customer.LegalName);
			}

			DataBase.Drop<CustomerContact>();
		}
Пример #6
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();
		}