Right, the MembershipUserCollection inherits ICollection (public sealed class 
MembershipUserCollection : ICollection, IEnumerable). The part of the 
documentation that you point out is where I got how to do the sqlmap settings. 
But it never showed an example of how to call it from code. Is there any 
examples of how to programmatically use QueryForList from code using a custom 
collection class? None of my examples that I've guessed are working.


From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: RE: How can I populate 
MembershipUserCollection instead of IList?Date: Tue, 25 Mar 2008 12:02:34 -0400



I'm having problems replying to the forum - so I'm replying to you.
I hope you will reply to the forum on my behalf. 
 
FROM Alon Hirsch:

Hi,
 
>From the documentation (PDF format) on physical page21 (of 107) (in the PDF it 
>is page 18:

In addition to providing the ability to return an IList of objects, the 
DataMapper supports the use of a
strongly-typed custom collection: a class that implements the 
System.Collections.CollectionBase abstract class.The following is an example of 
a CollectionBase class that can be used with the DataMapper 
A CollectionBase class can be specified for a select statement through the 
listClass attribute. The value of the
listClass attribute can be a Type Alias or the fully qualified name of a class. 
The statement should also indicate
the resultClass so that the DataMapper knows how to handle the type of objects 
in the collection. The
resultClass specified will be automatically mapped to the columns in the 
result, based on the result metadata.The following example shows a <statement> 
element with a listClass attribute 
Example 3.16. A <statement >element with listClass attribute
<statement id="GetAllAccounts"
listClass="AccountCollection"
resultClass="Account">
select
Account_ID as Id,
Account_FirstName as FirstName,
Account_LastName as LastName,
Account_Email as EmailAddress
from Accounts
order by Account_LastName, Account_FirstName</statement> I believe that IF you 
can return the existing System.MembershipUserCollection - this is how you will 
have to do it .  I'm not sure if it will work as the document states that the 
collection must implement the CollectionBase interface - I haven't had a look 
at what it implements or inherits(but it might):Example 3.15. A 
System.Collections.CollectionBase implementationusing System;using 
System.Collections;namespace WebShop.Domain{public class AccountCollection : 
CollectionBase{public AccountCollection() {}public Account this[int index]{get 
{ return (Account)List[index]; }set { List[index] = value; }}


From: [EMAIL PROTECTED]: [EMAIL PROTECTED]: RE: How can I populate 
MembershipUserCollection instead of IList?Date: Tue, 25 Mar 2008 11:13:20 -0400

Thanks but I still can't the syntax right. Initially I used QueryForObject 
because I thought I was returning a single MembershipUserCollection object with 
MembershipUsers within it. But now I'm trying to use QueryForList and it won't 
work because it is returning an IList type instead of MembershipUserCollection. 
I tried casting it to MembershipUserCollection and even tried getting just the 
first IList element, but nothing works. Are you sure I should use QueryForList 
because it's using IList instead of the collection class? This is what I tried: 
// Compile error: Cannot convert type // 
'System.Collections.Generic.IList<System.Web.Security.MembershipUserCollection>'
 to // 'System.Web.Security.MembershipUserCollection' via a reference 
conversion, boxing conversion, unboxing conversion, wrapping conversion, or 
null type conversionpublic static MembershipUserCollection GetAllUsers(){return 
DataPortal.Users.QueryForList("select-all-users", null)as 
MembershipUserCollection;} // Compile error: Cannot convert type 
'System.Collections.IList' to // 'System.Web.Security.MembershipUserCollection' 
via a reference conversion, boxing conversion, // unboxing conversion, wrapping 
conversion, or null type conversionpublic static MembershipUserCollection 
GetAllUsers(){return 
DataPortal.Users.QueryForList<MembershipUserCollection>("select-all-users", 
null)as MembershipUserCollection;} // Compiler error: Unable to cast object of 
type 'System.Web.Security.MembershipUserCollection' // to type 
'System.Collections.Generic.IList`1[System.Web.Security.MembershipUserCollection]'.public
 static MembershipUserCollection GetAllUsers(){return 
DataPortal.Users.QueryForList<MembershipUserCollection>("select-all-users", 
null)[0]as MembershipUserCollection;}   > Subject: RE: How can I populate 
MembershipUserCollection instead of IList?> Date: Tue, 25 Mar 2008 16:40:50 
+0200> From: [EMAIL PROTECTED]> To: [email protected]> > Hi,> > You 
should be using QueryForList - QueryForObject will return a SINGLE> object 
where your query (and what you want) returns a collection of> objects (multiple 
rows)> > HTH,> > Alon> > Alon Hirsch| eBAM Systems| Systems Developer> *: [+ 
27] (0)11 719-2222|*: [+27] (0)83 500-0066 |*: [+27] (0)11> 719-2051> *: [EMAIL 
PROTECTED]|*: http://www.ebam.co.za > > > > > -----Original Message-----> From: 
dCyphr [mailto:[EMAIL PROTECTED] > Sent: 25 March 2008 04:37 PM> To: 
[email protected]> Subject: Re: How can I populate 
MembershipUserCollection instead of> IList?> > > Thanks, I don't know how I 
missed that. But I've been toying with it and> I can't get it quite right. It 
keeps returning null. Am I right to use> QueryForObject? This is what I have 
but I don't know what I'm doing> wrong:> > SqlMap.config:> <alias>> <typeAlias 
alias="MembershipUser"> type="System.Web.Security.MembershipUser, System.Web, 
Version=2.0.0.0,> Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />> 
<typeAlias alias="MembershipUserCollection"> 
type="System.Web.Security.MembershipUserCollection, System.Web,> 
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />> 
</alias>> > <resultMaps>> <resultMap id="MembershipUserResult" 
class="MembershipUser">> <constructor>> <argument argumentName="providerName" 
column="ProviderName"> type="string" dbType="VarChar" />> <argument 
argumentName="name" column="UserName" type="string"> dbType="VarChar" />> 
<argument argumentName="providerUserKey" column="UserID"> type="object" 
dbType="VarChar" />> <argument argumentName="email" column="Email" 
type="string"> dbType="VarChar" />> <argument argumentName="passwordQuestion"> 
column="PasswordQuestion" type="string" dbType="VarChar" />> <argument 
argumentName="comment" column="Comment"> type="string"> dbType="VarChar" />> 
<argument argumentName="isApproved" column="IsApproved"> type="bool" 
dbType="Boolean" />> <argument argumentName="isLockedOut" column="IsLockedOut"> 
type="bool" dbType="Boolean" />> <argument argumentName="creationDate" 
column="DateCreated"> type="dateTime" dbType="Date" />> <argument 
argumentName="lastLoginDate" column="LastLoginDate"> type="dateTime" 
dbType="Date" />> <argument argumentName="lastActivityDate"> 
column="DateModified"> type="dateTime" dbType="Date" />> <argument 
argumentName="lastPasswordChangedDate"> column="LastPasswordChangedDate" 
type="dateTime" dbType="Date" />> <argument argumentName="lastLockoutDate"> 
column="LastLockoutDate"> type="dateTime" dbType="Date" />> </constructor>> 
</resultMap>> </resultMaps>> > <select id="select-all-users" 
listClass="MembershipUserCollection"> resultMap="MembershipUserResult">> SELECT 
*> FROM Memberships> </select>> > .NET implementation:> public 
MembershipUserCollection GetAllUsers()> {> try> {> return> 
DataPortal.Users.QueryForObject("select-all-users",> null) > as 
MembershipUserCollection;> }> catch> {> throw;> }> }> > All my other sql 
methods work and am able to get a single MembershipUser> (I have to use the 
resultsMap to feed the constructor because Microsoft> doesn't allow any other 
way to populate an existing MembershipUser, many> read-only properties). But 
when I use the listClass above, it compiles> fine but it returns null. I've 
also tried <statement> instead of> <select> and the same problem happens. What 
am I missing??> > > dCyphr wrote:> > > > I'm trying to implement the GetAllUser 
method in the Membership > > Provider and I have to return a 
MembershipUserCollection populated > > with MembershipUser objects. Is this 
possible? I'm pretty much looking> > > for (which doesn't exist of course):> > 
> > public T QueryForCollection<T, U>> > > > where T would be 
MembershipUserCollection and U would be> MembershipUser.> > Is there any way to 
achieve something like this? My only option I can > > think of is loading the 
IList with MembershipUsers, then loop thru the> > > IList and populate a 
MembershipUserCollection one by one in my code, > > but that's really 
redundant. Any ideas?> > > > --> View this message in context:> 
http://www.nabble.com/How-can-I-populate-MembershipUserCollection-instea> 
d-of-IList--tp16184430p16275132.html> Sent from the iBATIS - User - Cs mailing 
list archive at Nabble.com.> 

How well do you know your celebrity gossip? Talk celebrity smackdowns here. 

Watch “Cause Effect,” a show about real people making a real difference. Learn 
more. 
_________________________________________________________________
How well do you know your celebrity gossip?
http://originals.msn.com/thebigdebate?ocid=T002MSN03N0707A

Reply via email to