Esempio n. 1
0
        /// <summary>
        /// Executes queries and converts records to objects using specified ctor and property mappings.
        /// </summary>
        static void GetDataUsingCtor()
        {
            var propertyMappings = new PropertyColumnMapping[] {
                new PropertyColumnMapping("Name", typeof(string))
            };

            var ctorMappings = new ColumnConstructorParameterMappingCollection<Company>(new Type[] { typeof(int), typeof(string) });
            ctorMappings.Add("CompanyID", 0);
            ctorMappings.Add("RegistryNumber", 1);

            var company = GetSingleCompany(ctorMappings, propertyMappings);

            Console.WriteLine("\nCompany 3 is {0} {1}\n", company.Registry, company.Name);

            company = GetFirstCompany(ctorMappings, propertyMappings);

            Console.WriteLine("1st company is {0} {1}\n", company.Registry, company.Name);

            var companies = GetAllCompanies(ctorMappings, propertyMappings);

            Console.WriteLine("Companies are");

            foreach (var c in companies)
            {
                Console.WriteLine("{0}: {1} {2}", c.ID, c.Registry, c.Name);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Executes queries and converts records to objects using default constructor
        /// and specified property mappings.
        /// </summary>
        static void GetDataUsingProperties()
        {
            var mappings = new PropertyColumnMapping[] {
                new PropertyColumnMapping("ID", "PersonID", typeof(int)),
                new PropertyColumnMapping("FirstName", typeof(string)),
                new PropertyColumnMapping("LastName", typeof(string))
            };

            Person person = GetSinglePerson(mappings);

            Console.WriteLine("Person 3 is {0} {1}\n", person.FirstName, person.LastName);

            person = GetFirstPerson(mappings);

            Console.WriteLine("1st Mouse is {0} {1}\n", person.FirstName, person.LastName);

            IEnumerable<Person> persons = GetAllPersons(mappings);

            Console.WriteLine("Persons are");

            foreach (var p in persons)
            {
                Console.WriteLine("{0}: {1} {2}", p.ID, p.FirstName, p.LastName);
            }
        }