Exemple #1
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;
        }
Exemple #2
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;
        }
Exemple #3
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;
        }