Email Reminder Code Bug

Jan 6, 2012 at 4:32 PM

 

Original code:

                        string.Format("select value o from FrameworkEntities.Users as where ToLower(o.Email) == {0}", emailAddress.ToLower()));

(Missing alias (before the where) and no single quotes around the {0} are the issues I believe.

 

(My fix) code below.

 

        public PasswordResetResultType ResetPassword(string emailAddress)
        {
            PasswordResetResultType result = PasswordResetResultType.Successful;
            try
            {
                using (FrameworkEntities c = new FrameworkEntities())
                {

                    // Just to make sure that eSQL really works!!
                    ObjectQuery<User> query = c.CreateQuery<User>(
                        string.Format("select VALUE ent from FrameworkEntities.Users as ent where ToLower(ent.Email) == '{0}'", emailAddress.ToLower()));
                    User userObject = query.FirstOrDefault();
                    if (userObject != null)
                    {