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
conversion
public 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 conversion
public 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?
http://originals.msn.com/thebigdebate?ocid=T002MSN03N0707A