ibatis-user-cs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Kierstead <br...@fluidmedia.com>
Subject Re: Problem with Generic IList as return type.
Date Mon, 28 Aug 2006 13:49:54 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Nikhil,<br>
<br>
You need to use the 2.0 binaries for iBatis - they have updated
versions of those functions that can accept a generic.&nbsp; So instead of
ExecuteQueryForList, you need to use ExecuteQueryForList&lt;T&gt; so
that it will work.<br>
<br>
Brian<br>
<br>
<br>
Nikhil Vaghela wrote:
<blockquote
 cite="midACEC0E8E588A6A40BD2026CA63D7496628A137@v2mailserver.in.v2solutions.com"
 type="cite">
  <meta http-equiv="Content-Type" content="text/html; ">
  <meta name="Generator" content="Microsoft Word 11 (filtered medium)">
  <style>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
pre
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:"Courier New";
	color:black;}
span.EmailStyle17
	{mso-style-type:personal-compose;
	font-family:Arial;
	color:windowtext;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
	{page:Section1;}
-->
  </style>
  <div class="Section1">
  <p class="MsoNormal"><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;">Hi,<o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;"><o:p>&nbsp;</o:p></span></font></p>
  <p class="MsoNormal"><b><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial; font-weight: bold;">Problem
overview<o:p></o:p></span></font></b></p>
  <p class="MsoNormal"><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;">I am going to use
iBatis.Net latest version which supports
.NET 2.0.<o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;"><o:p>&nbsp;</o:p></span></font></p>
  <p class="MsoNormal"><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;">I have a wrapper class as
given in the old example NPetShop that
is BaseSQLMapDao in my Persistance layer which is having methods like <b><span
 style="font-weight: bold;">&#8220;</span></b></span></font><b><font
 face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;; font-weight: bold;">ExecuteQueryForList&#8221;
  </span></font></b><font face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">which
actually calls sqlMapper&#8217;s QueryForList method of iBatisNet.DataMapper</span></font><font
 face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;"><o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;">Now .NET 2.0 supports
generic IList and iBatis also supports
this feature.<o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;"><o:p>&nbsp;</o:p></span></font></p>
  <p class="MsoNormal"><b><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial; font-weight: bold;">Actual
problem<o:p></o:p></span></font></b></p>
  <p class="MsoNormal"><b><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial; font-weight: bold;"><o:p>&nbsp;</o:p></span></font></b></p>
  <p class="MsoNormal"><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;">I will be calling
ExecuteQueryForList method from my BuisnessObject&#8217;s
sqlMapDao say for example &#8220;EmployeeSqlMapDao.cs&#8221; or
&#8220;DepartmentSqlMapDao.cs&#8221;
in my persistence layer.<o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;"><o:p>&nbsp;</o:p></span></font></p>
  <p class="MsoNormal"><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;">Now the problem is if I
use genericsList my BaseSqlMapDao
doest not know which type of IList it is returning !!!!<o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;">e.g<o:p></o:p></span></font></p>
  <p class="MsoNormal"><font color="blue" face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">public</span></font><font
 face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">
  <font color="teal"><span style="color: teal;">IList</span></font>
GetEmployeeListForDepartment(<font color="blue"><span
 style="color: blue;">string</span></font>
DepartmentID)<o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">{<o:p></o:p></span></font></p>
  <p class="MsoNormal" style="text-indent: 0.5in;"><font color="blue"
 face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">return</span></font><font
 face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">
ExecuteQueryForList(<font color="maroon"><span style="color: maroon;">"GetEmployeesForDepartment"</span></font>,
DepartmentID);&nbsp;&nbsp; <o:p></o:p></span></font></p>
  <p class="MsoNormal" style="text-indent: 0.5in;"><font
 face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">//above given is
a method of
BaseSqlMapDao class<o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">}<o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;"><o:p>&nbsp;</o:p></span></font></p>
  <p class="MsoNormal"><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;">this works fine <o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;">but if I use generic
IList like as follows<o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;"><o:p>&nbsp;</o:p></span></font></p>
  <p class="MsoNormal"><font color="blue" face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;; color: blue;">public</span></font><font
 face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">
  <font color="teal"><span style="color: teal;">IList&lt;Employee&gt;</span></font>
GetEmployeeListForDepartment(<font color="blue"><span
 style="color: blue;">string</span></font>
DepartmentID)<o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">{<o:p></o:p></span></font></p>
  <p class="MsoNormal" style="text-indent: 0.5in;"><font color="blue"
 face="Courier New" size="2"><span
 style="background: silver none repeat scroll 0%; font-size: 10pt; font-family: &quot;Courier
New&quot;; color: blue; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial;
-moz-background-inline-policy: -moz-initial;">return</span></font><font
 face="Courier New" size="2"><span
 style="background: silver none repeat scroll 0%; font-size: 10pt; font-family: &quot;Courier
New&quot;; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy:
-moz-initial;">
ExecuteQueryForList(<font color="maroon"><span style="color: maroon;">"GetEmployeesForDepartment"</span></font>,
DepartmentID);</span></font><font face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">&nbsp;&nbsp;
<o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">}<o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">Now what will i
be having as return type in this
case for ExecuteQueryForList as that method does not know which type of
Objects
are stored in the Ilist!!!! And if I make its return type
IList&lt;Object&gt; i
will have to cast it each and every item in IList&lt;Object&gt; to my
custome
object&#8217;s Ilist&lt;MyCustomObject&gt; which I don&#8217;t want as its
not
good method <o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;"><o:p>&nbsp;</o:p></span></font></p>
  <p class="MsoNormal"><font face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">So how can I
solve the problem ???? I hope I could
describe my question properly.<o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;"><o:p>&nbsp;</o:p></span></font></p>
  <p class="MsoNormal"><font face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">Any help will be
greatly appreciated.<o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">Thanks.<o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Courier New" size="2"><span
 style="font-size: 10pt; font-family: &quot;Courier New&quot;;">Nikhil.</span></font><font
 face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;"><o:p></o:p></span></font></p>
  <p class="MsoNormal"><font face="Arial" size="2"><span
 style="font-size: 10pt; font-family: Arial;"><o:p>&nbsp;</o:p></span></font></p>
  <p class="MsoNormal"><font face="Times New Roman" size="3"><span
 style="font-size: 12pt;"><o:p>&nbsp;</o:p></span></font></p>
  </div>
</blockquote>
<br>
</body>
</html>


Mime
View raw message