views:

43

answers:

3

Hi

I want to send out an email to all users where their birthday is today

i am using the built-in asp.net (3.5) membership. All users have a profile (stored in aspnet_Profile) which contains a date/time property called 'birthday'. I need to get a list of users email addresses from the 'aspnet_Membership' table where a users birthday is today, along with the users 'firstname' which is string property in the aspnet_Profile table.

i would like a list returned preferrably using C# LINQ.

i am not sure how to access the birthday property in the profile table, based on the way it is stored in the db table i.e name/value columns

thank you kb

+2  A: 

I think you should consider changing to the much-improved table based provider:

http://weblogs.asp.net/scottgu/archive/2006/01/10/435038.aspx

This allows you to separate your data into one value per table column in the standard SQL way. This performs petter than the standard provider and it solves your problem of querying the Profiles database.

It will take a small amount of work to convert the database, but on the code side, it is just a matter of configuring in a different provider and nothing else should change. That is the beaurty of the provider pattern.

Daniel Dyson
thanks @Daniel i wasnt even aware of that provider, will certainly be using this going forward!
kb
You're welcome.
Daniel Dyson
A: 

I don't use LINQ enough to give you a good answer, but the following may be the underlying SQL you need (This is how my SSMS generated it in the query designer):

SELECT     aspnet_Profile.PropertyValuesString AS firstname, aspnet_Membership.Email
FROM         aspnet_Profile INNER JOIN
                      aspnet_Membership ON aspnet_Profile.UserId = aspnet_Membership.UserId INNER JOIN
                      aspnet_Profile AS aspnet_Profile_1 ON aspnet_Profile.UserId = aspnet_Profile_1.UserId
WHERE     (aspnet_Profile_1.PropertyNames LIKE N'birthday') AND (aspnet_Profile.PropertyNames LIKE N'firstname') AND (DATEADD(dd, 0, DATEDIFF(dd, 0, 
                      aspnet_Profile_1.PropertyValuesString)) = DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())))
Tobiasopdenbrouw
A: 

Hey,

The Profile mechanism parses the values out by splitting each name/value pair up, and then parsing them individually. You could write code to do that yourself. Or you could follow @Daniel's approach and use the alternative provider, which makes life easier. The out-of-the-box provider is a pain with the string concatenation.

Is this code in the same app? You could just use the profile object to retrieve it, if you are talking C#... what context is this piece of code in? Batch service?

HTH.

Brian