■ ISqlMapper 인터페이스의 QueryForObject 메소드를 사용해 데이터 행 수를 구하는 방법을 보여준다.
▶ providers.config
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?xml version="1.0" encoding="utf-8"?> <providers xmlns="http://ibatis.apache.org/providers" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <clear/> <provider name="PostgreSql4.0.7.0" description="PostgreSql, Npgsql provider V4.0.7.0" assemblyName="Npgsql, Version=4.0.7.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" connectionClass="Npgsql.NpgsqlConnection" commandClass="Npgsql.NpgsqlCommand" parameterClass="Npgsql.NpgsqlParameter" parameterDbTypeClass="NpgsqlTypes.NpgsqlDbType" parameterDbTypeProperty="NpgsqlDbType" dataAdapterClass="Npgsql.NpgsqlDataAdapter" commandBuilderClass="Npgsql.NpgsqlCommandBuilder" usePositionalParameters="false" useParameterPrefixInSql="true" useParameterPrefixInParameter="true" parameterPrefix=":" allowMARS="true" enabled="true" default="true" /> </providers> |
▶ sql.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<?xml version="1.0" encoding="utf-8" ?> <sqlMap namespace="TestProject" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <statements> <statement id="GetDataCount" parameterClass="System.Int32" resultClass="System.String"> SELECT COUNT(1) AS CNT FROM PUBLIC.LIBRARY_DATA WHERE MENU_ID = #value# </statement> </statements> </sqlMap> |
▶ SqlMap.config
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?xml version="1.0" encoding="utf-8" ?> <sqlMapConfig xmlns="http://ibatis.apache.org/dataMapper" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <settings> <setting useStatementNamespaces="false" /> <setting cacheModelsEnabled="true" /> <setting validateSqlMap="true" /> </settings> <database> <provider name="PostgreSql4.0.7.0" /> <dataSource name="TestDB" connectionString="Host=127.0.0.1;Port=5432;Database=TestDB;User ID=postgres;Password=postgres;" /> </database> <sqlMaps> <sqlMap embedded="sql.xml, TestProject" /> </sqlMaps> </sqlMapConfig> |
▶ Program.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
using System; using IBatisNet.DataMapper; namespace ConsoleApplication1 { /// <summary> /// 프로그램 /// </summary> public class Program { //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 프로그램 시작하기 - Main() /// <summary> /// 프로그램 시작하기 /// </summary> private static void Main() { int count = Mapper.Instance().QueryForObject<int>("GetDataCount", "439BE38B-F7CD-447A-9266-54F906A22A7B"); Console.WriteLine(count); } #endregion } } |