ibatis-user-cs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gentile, Wayne \(Hitachi Consulting\)" <wayne.gentile-...@eds.com>
Subject RE: Problem with Generic IList as return type.
Date Mon, 28 Aug 2006 13:52:54 GMT
Create an overloaded ExecuteQueryForList with the following signature:

	public IList<T> ExecuteQueryForList<T>(string queryName, object
args)

You will then need to change your calls to ExecuteQueryForList to pass
in the generic type, as in:
	IList<Employee> employeeList =
ExecuteQueryForList<Employee>("GetEmployeesForDepartment",
departmentID);

-----Original Message-----
From: Matt Grande [mailto:matt.grande@fluidmedia.com] 
Sent: Monday, August 28, 2006 8:39 AM
To: user-cs@ibatis.apache.org
Subject: Re: Problem with Generic IList as return type.

Hi Nikhil,

I played around generics a couple weeks ago and, as far as I can tell,
there's no way to do what you're asking.

The only way to do it is to loop through each list item, and assign it
to the new (generic) list.

Sorry I couldn't be more helpful,

- Matt.

On Mon, 2006-28-08 at 10:26 +0530, Nikhil Vaghela wrote:
> Hi,
> 
>  
> 
> Problem overview
> 
> I am going to use iBatis.Net latest version which supports .NET 2.0.
> 
>  
> 
> I have a wrapper class as given in the old example NPetShop that is
> BaseSQLMapDao in my Persistance layer which is having methods like
> "ExecuteQueryForList" which actually calls sqlMapper's QueryForList
> method of iBatisNet.DataMapper
> 
> Now .NET 2.0 supports generic IList and iBatis also supports this
> feature.
> 
>  
> 
> Actual problem
> 
>  
> 
> I will be calling ExecuteQueryForList method from my BuisnessObject's
> sqlMapDao say for example "EmployeeSqlMapDao.cs" or
> "DepartmentSqlMapDao.cs" in my persistence layer.
> 
>  
> 
> Now the problem is if I use genericsList my BaseSqlMapDao doest not
> know which type of IList it is returning !!!!
> 
> e.g
> 
> publicIList GetEmployeeListForDepartment(string DepartmentID)
> 
> {
> 
> return ExecuteQueryForList("GetEmployeesForDepartment",
> DepartmentID);   
> 
> //above given is a method of BaseSqlMapDao class
> 
> }
> 
>  
> 
> this works fine 
> 
> but if I use generic IList like as follows
> 
>  
> 
> publicIList<Employee> GetEmployeeListForDepartment(string
> DepartmentID)
> 
> {
> 
> return ExecuteQueryForList("GetEmployeesForDepartment",
> DepartmentID);   
> 
> }
> 
> 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<Object> i will have to cast it each and every item in
> IList<Object> to my custome object's Ilist<MyCustomObject> which I
> don't want as its not good method 
> 
>  
> 
> So how can I solve the problem ???? I hope I could describe my
> question properly.
> 
>  
> 
> Any help will be greatly appreciated.
> 
> Thanks.
> 
> Nikhil.
> 
>  
> 
>  
> 
> 



Mime
View raw message