Example #1
0
        /// <summary>
        /// Executes query that returns all records.
        /// </summary>
        static IEnumerable<Person> GetAllPersons(IEnumerable<PropertyColumnMapping> mappings)
        {
            string sql = "SELECT * FROM Person;";

            var settings = new SqlCommandSettings(sql, CommandType.Text);

            var executor = new SqlExecutor(cs);

            var persons = executor.GetRecords<Person>(settings, mappings);

            return persons;
        }
Example #2
0
        /// <summary>
        /// Executes query that might return multiple records, but only takes 1st one.
        /// </summary>
        static IEnumerable<Company> GetAllCompanies(ColumnConstructorParameterMappingCollection<Company> ctorMappings, IEnumerable<PropertyColumnMapping> propMappings)
        {
            string sql = "SELECT * FROM Company;";

            var settings = new SqlCommandSettings(sql, CommandType.Text);

            var executor = new SqlExecutor(cs);

            var companies = executor.GetRecords<Company>(settings, ctorMappings, propMappings);

            return companies;
        }
Example #3
0
        /// <summary>
        /// Executes query that expects only 1 record to be returned.
        /// </summary>
        static Person GetSinglePerson(IEnumerable<PropertyColumnMapping> mappings)
        {
            string sql = "SELECT * FROM Person WHERE PersonID = @id;";

            var settings = new SqlCommandSettings(sql, CommandType.Text);
            settings.AddParameter(new SqlParameter("@id", 3));

            var executor = new SqlExecutor(cs);

            var person = executor.GetSingleRecord<Person>(settings, mappings);

            return person;
        }
Example #4
0
        /// <summary>
        /// Executes query that expects only 1 record to be returned.
        /// </summary>
        static Company GetSingleCompany(ColumnConstructorParameterMappingCollection<Company> ctorMappings, IEnumerable<PropertyColumnMapping> propMappings)
        {
            string sql = "SELECT * FROM Company WHERE CompanyID = @id;";

            int id = 3;

            var settings = new SqlCommandSettings(sql, CommandType.Text);
            settings.AddParameter(new SqlParameter("@id", id));

            var executor = new SqlExecutor(cs);

            var company = executor.GetSingleRecord<Company>(settings, ctorMappings, propMappings);

            return company;
        }
Example #5
0
        /// <summary>
        /// Executes query that might return multiple records, but only takes 1st one.
        /// </summary>
        static Person GetFirstPerson(IEnumerable<PropertyColumnMapping> mappings)
        {
            string sql = "SELECT * FROM Person WHERE LastName = @lastName;";

            var settings = new SqlCommandSettings(sql, CommandType.Text);
            settings.AddParameter(new SqlParameter("@lastName", "Mouse"));

            var executor = new SqlExecutor(cs);

            var person = executor.GetFirstRecord<Person>(settings, mappings);

            return person;
        }
Example #6
0
        /// <summary>
        /// Executes query that might return multiple records, but only takes 1st one.
        /// </summary>
        static Company GetFirstCompany(ColumnConstructorParameterMappingCollection<Company> ctorMappings, IEnumerable<PropertyColumnMapping> propMappings)
        {
            string sql = "SELECT * FROM Company WHERE RegistryNumber LIKE '788%';";

            var settings = new SqlCommandSettings(sql, CommandType.Text);

            var executor = new SqlExecutor(cs);

            var company = executor.GetFirstRecord<Company>(settings, ctorMappings, propMappings);

            return company;
        }