By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,996 Members | 1,526 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,996 IT Pros & Developers. It's quick & easy.

extending MembershipUser, need help!

P: n/a
Hey

ASP.NET 2.0

I'm trying to extend the MembershipUser class, and have encounter a problem:

<< See in the middle of this post for info about why I do this >>
<< See below of this post for the source code of Contact class >>

public class Contact : MembershipUser
{
public Contact(string username)
{
this.UserName = username;
}
}

UserName is readonly so "this.UserName = username;" gives an error.

Anybody have a suggestion on how to this???

*********************************************
Why am I extending MembershipUser class:

I do this because I'm developing a networking website and this code should
return a members friends. This MembershipUserCollection should display the
friends in a GridView

public static MembershipUserCollection GetContacts(string user)
{
MembershipUserCollection contacts = null;
List<ContactDetailrecordset =
SiteProvider.Networking.GetContacts(user);
contacts = GetContactListFromContactDetailsList(recordset);

return contacts;
}
It's 3 reasons why I do it:
- It is part of N-tier design, this is in the BLL layer. the DAL layer has
sent a collection of objects (each object holding info about a username). An
the task for GetContacts is to convert that list of objects into a
MembershipUserCollection
- The result of GetContacts will be used in a GridView, which already are
showing data based on MembershipUserCollection
- It's the best solution I know of... but please, please if you think my
approach sucks then please give me some tips about how you think this should
be done. I love to learn you things and believe many developers have better
approach on this

Any suggestions??

************************************************** *
Entire source code of Contact:
using System;
using System.Data;
using System.Web.Security;
using System.Collections.Generic;
using AH.MyNetwork.DAL;
/// <summary>
/// Summary description for Contact
/// </summary>
public class Contact : MembershipUser
{

public Contact(string username)
{
this.UserName = username;
}

public static MembershipUserCollection GetContacts(string user)
{
MembershipUserCollection contacts = null;
List<ContactDetailrecordset =
SiteProvider.Networking.GetContacts(user);
contacts = GetContactListFromContactDetailsList(recordset);

return contacts;
}

private static MembershipUserCollection
GetContactListFromContactDetailsList(List<ContactD etailrecordset)
{
MembershipUserCollection contacts = null;
foreach (ContactDetail record in recordset)
contacts.Add(GetContactFromContactDetails(record)) ;
return contacts;
}

private static Contact GetContactFromContactDetails(ContactDetail
record)
{
if (record == null)
return null;
else
{
return new Contact(record.USERNAME);
}
}

}
Jeff
Mar 28 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
MembershipUser's constructor allows passing the username (along with
several other values). just call it from your constructor.
-- bruce (sqlwork.com)
Jeff wrote:
Hey

ASP.NET 2.0

I'm trying to extend the MembershipUser class, and have encounter a problem:

<< See in the middle of this post for info about why I do this >>
<< See below of this post for the source code of Contact class >>

public class Contact : MembershipUser
{
public Contact(string username)
{
this.UserName = username;
}
}

UserName is readonly so "this.UserName = username;" gives an error.

Anybody have a suggestion on how to this???

*********************************************
Why am I extending MembershipUser class:

I do this because I'm developing a networking website and this code should
return a members friends. This MembershipUserCollection should display the
friends in a GridView

public static MembershipUserCollection GetContacts(string user)
{
MembershipUserCollection contacts = null;
List<ContactDetailrecordset =
SiteProvider.Networking.GetContacts(user);
contacts = GetContactListFromContactDetailsList(recordset);

return contacts;
}
It's 3 reasons why I do it:
- It is part of N-tier design, this is in the BLL layer. the DAL layer has
sent a collection of objects (each object holding info about a username). An
the task for GetContacts is to convert that list of objects into a
MembershipUserCollection
- The result of GetContacts will be used in a GridView, which already are
showing data based on MembershipUserCollection
- It's the best solution I know of... but please, please if you think my
approach sucks then please give me some tips about how you think this should
be done. I love to learn you things and believe many developers have better
approach on this

Any suggestions??

************************************************** *
Entire source code of Contact:
using System;
using System.Data;
using System.Web.Security;
using System.Collections.Generic;
using AH.MyNetwork.DAL;
/// <summary>
/// Summary description for Contact
/// </summary>
public class Contact : MembershipUser
{

public Contact(string username)
{
this.UserName = username;
}

public static MembershipUserCollection GetContacts(string user)
{
MembershipUserCollection contacts = null;
List<ContactDetailrecordset =
SiteProvider.Networking.GetContacts(user);
contacts = GetContactListFromContactDetailsList(recordset);

return contacts;
}

private static MembershipUserCollection
GetContactListFromContactDetailsList(List<ContactD etailrecordset)
{
MembershipUserCollection contacts = null;
foreach (ContactDetail record in recordset)
contacts.Add(GetContactFromContactDetails(record)) ;
return contacts;
}

private static Contact GetContactFromContactDetails(ContactDetail
record)
{
if (record == null)
return null;
else
{
return new Contact(record.USERNAME);
}
}

}
Jeff

Mar 28 '07 #2

P: n/a
yeah, I know. But I have only the username and then I would need to set the
other values to NULL... I could try to do that... maybe somebody here has a
better approach:

In DAL a method returns a collection of objects (each object holding a
user's name - username). The task of BLL is to convert this collection of
objects into a MembershipUserCollection.... But hey what if the DAL instead
returned a MembershipUserCollection... I'll try that instead....

Any suggestion/opinions about this??

Jeff

"bruce barker" <no****@nospam.comwrote in message
news:eC****************@TK2MSFTNGP02.phx.gbl...
MembershipUser's constructor allows passing the username (along with
several other values). just call it from your constructor.
-- bruce (sqlwork.com)
Jeff wrote:
>Hey

ASP.NET 2.0

I'm trying to extend the MembershipUser class, and have encounter a
problem:

<< See in the middle of this post for info about why I do this >>
<< See below of this post for the source code of Contact class >>

public class Contact : MembershipUser
{
public Contact(string username)
{
this.UserName = username;
}
}

UserName is readonly so "this.UserName = username;" gives an error.

Anybody have a suggestion on how to this???

*********************************************
Why am I extending MembershipUser class:

I do this because I'm developing a networking website and this code
should return a members friends. This MembershipUserCollection should
display the friends in a GridView

public static MembershipUserCollection GetContacts(string user)
{
MembershipUserCollection contacts = null;
List<ContactDetailrecordset =
SiteProvider.Networking.GetContacts(user);
contacts = GetContactListFromContactDetailsList(recordset);

return contacts;
}
It's 3 reasons why I do it:
- It is part of N-tier design, this is in the BLL layer. the DAL layer
has sent a collection of objects (each object holding info about a
username). An the task for GetContacts is to convert that list of objects
into a MembershipUserCollection
- The result of GetContacts will be used in a GridView, which already are
showing data based on MembershipUserCollection
- It's the best solution I know of... but please, please if you think my
approach sucks then please give me some tips about how you think this
should be done. I love to learn you things and believe many developers
have better approach on this

Any suggestions??

************************************************* **
Entire source code of Contact:
using System;
using System.Data;
using System.Web.Security;
using System.Collections.Generic;
using AH.MyNetwork.DAL;
/// <summary>
/// Summary description for Contact
/// </summary>
public class Contact : MembershipUser
{

public Contact(string username)
{
this.UserName = username;
}

public static MembershipUserCollection GetContacts(string user)
{
MembershipUserCollection contacts = null;
List<ContactDetailrecordset =
SiteProvider.Networking.GetContacts(user);
contacts = GetContactListFromContactDetailsList(recordset);

return contacts;
}

private static MembershipUserCollection
GetContactListFromContactDetailsList(List<Contact Detailrecordset)
{
MembershipUserCollection contacts = null;
foreach (ContactDetail record in recordset)
contacts.Add(GetContactFromContactDetails(record)) ;
return contacts;
}

private static Contact GetContactFromContactDetails(ContactDetail
record)
{
if (record == null)
return null;
else
{
return new Contact(record.USERNAME);
}
}

}
Jeff

Mar 28 '07 #3

P: n/a
This is interesting. I've had it on my mind myself.

I'm reading the way you put it and what does it say to me?
It says "I do this because I'm developing a networking website and this code
should return a members friends" which says to relational model that uses a
"foreign key" used to relate to table(s) of his or her friends. So why not
store a key in the Profile object?

<%= Clinton Gallagher
NET csgallagher AT metromilwaukee.com
URL http://clintongallagher.metromilwaukee.com/


"Jeff" <it************@hotmail.com.NOSPAMwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
yeah, I know. But I have only the username and then I would need to set
the other values to NULL... I could try to do that... maybe somebody here
has a better approach:

In DAL a method returns a collection of objects (each object holding a
user's name - username). The task of BLL is to convert this collection of
objects into a MembershipUserCollection.... But hey what if the DAL
instead returned a MembershipUserCollection... I'll try that instead....

Any suggestion/opinions about this??

Jeff

"bruce barker" <no****@nospam.comwrote in message
news:eC****************@TK2MSFTNGP02.phx.gbl...
>MembershipUser's constructor allows passing the username (along with
several other values). just call it from your constructor.
-- bruce (sqlwork.com)
Jeff wrote:
>>Hey

ASP.NET 2.0

I'm trying to extend the MembershipUser class, and have encounter a
problem:

<< See in the middle of this post for info about why I do this >>
<< See below of this post for the source code of Contact class >>

public class Contact : MembershipUser
{
public Contact(string username)
{
this.UserName = username;
}
}

UserName is readonly so "this.UserName = username;" gives an error.

Anybody have a suggestion on how to this???

*********************************************
Why am I extending MembershipUser class:

I do this because I'm developing a networking website and this code
should return a members friends. This MembershipUserCollection should
display the friends in a GridView

public static MembershipUserCollection GetContacts(string user)
{
MembershipUserCollection contacts = null;
List<ContactDetailrecordset =
SiteProvider.Networking.GetContacts(user);
contacts = GetContactListFromContactDetailsList(recordset);

return contacts;
}
It's 3 reasons why I do it:
- It is part of N-tier design, this is in the BLL layer. the DAL layer
has sent a collection of objects (each object holding info about a
username). An the task for GetContacts is to convert that list of
objects into a MembershipUserCollection
- The result of GetContacts will be used in a GridView, which already
are showing data based on MembershipUserCollection
- It's the best solution I know of... but please, please if you think my
approach sucks then please give me some tips about how you think this
should be done. I love to learn you things and believe many developers
have better approach on this

Any suggestions??

************************************************ ***
Entire source code of Contact:
using System;
using System.Data;
using System.Web.Security;
using System.Collections.Generic;
using AH.MyNetwork.DAL;
/// <summary>
/// Summary description for Contact
/// </summary>
public class Contact : MembershipUser
{

public Contact(string username)
{
this.UserName = username;
}

public static MembershipUserCollection GetContacts(string user)
{
MembershipUserCollection contacts = null;
List<ContactDetailrecordset =
SiteProvider.Networking.GetContacts(user);
contacts = GetContactListFromContactDetailsList(recordset);

return contacts;
}

private static MembershipUserCollection
GetContactListFromContactDetailsList(List<Contac tDetailrecordset)
{
MembershipUserCollection contacts = null;
foreach (ContactDetail record in recordset)
contacts.Add(GetContactFromContactDetails(record)) ;
return contacts;
}

private static Contact GetContactFromContactDetails(ContactDetail
record)
{
if (record == null)
return null;
else
{
return new Contact(record.USERNAME);
}
}

}
Jeff


Mar 29 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.