Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7964427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:53:21+00:00 2026-06-04T05:53:21+00:00

I have method where I need to retrieve using EF the last ten entries

  • 0

I have method where I need to retrieve using EF the last ten entries in the database and check to see if there is a match between the value and the current term. Here is what I have thus far

public static int ValidatePassword(string username, string password, int securityUserId)
        {
                int validResult = 0;
                /*Need to pass to client a value based upon success or failure of validation
                 * 0 - success
                 * 1 - password has already been used in the last 10 entries
                 * 2 - password does not meet CJIS requirements
                 */
                IEnumerable<string> oldpassword = null;
                // Create a Regular Expression to determine whether or not special characters are present.
                Regex regularExpression = new Regex("[^a-z0-9]");

                //if id exists pull last ten passwords
                if (securityUserId > 0)
                {
                    long id = Convert.ToInt64(securityUserId);

                    using (var context = new SecurityEntities(string.Empty))
                    {
                        try
                        {
                            oldpassword = (from p in context.SecurityAudits
                                           where p.SecurityUserId == id &&
                                           p.OldPassword == password
                                           orderby p.ActionDate descending
                                           select p.OldPassword.Take(10).ToString()).ToList();
                        }
                        catch (Exception ex)
                        {
                            string err = string.Format("ValidateCJISPassword() was unable to return an object msg:{0}", ex.Message);
                            throw new Exception(err, ex.InnerException);
                        }
                        finally
                        {
                            context.Dispose();
                        }
                    }
                }

                else if (oldpassword == null)
                {
                    //no matching record found now check other requirements
                    if ((password.Length >= DEFAULT_CJIS_PASSWORD_MIN_LENGTH) && regularExpression.IsMatch(password) && (password != username))
                    {
                        //success
                        validResult = 0;
                    }
                    else
                    {
                        //password does not meet standard CJIS requirements
                        validResult = 2;
                    }
                }
                else
                {
                    //matching record was found
                    validResult = 1;
                }
                return validResult;
            }
}

Where I am currently hung up is the query throws an exception on the ToString() method

LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.

I’m still learning EF and how linq works so I’m not sure what the best approach here is. Should I try to set the result to something other than IEnumerable like an array or List or is there another approach I should consider?

Thanks in advance,

Cheers,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T05:53:23+00:00Added an answer on June 4, 2026 at 5:53 am

    Change this

    oldpassword = (from p in context.SecurityAudits
                       where p.SecurityUserId == id &&
                       p.OldPassword == password
                       orderby p.ActionDate descending
                       select p.OldPassword.Take(10).ToString()).ToList();
    

    To this

    oldpassword = (from p in context.SecurityAudits
                   where p.SecurityUserId == id &&
                   p.OldPassword == password
                   orderby p.ActionDate descending
                   select p.OldPassword).Take(10).ToList();
    

    The problem was that your Take(10) clause was not part of the whole result but inside the actual linq statement.. it goes on the outside of it to take the top 10 of the entire resultset.. then you do the ToList() which turns the whole thing into an array

    The next problem is that you just created an array and assigned it to oldpassword

    I don’t see anything here that does anything with the array…

    You need to do something like:

    1. declare your array of strings
    2. assign the array to the return of the linq query
    3. evaluate the return for > 0 results
    4. if > 0 then the password has been used in the last 10
    5. if = 0 then new password should be ok, correct?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have method in a class that I need to make sure is only
I have this method that changes an larger image source on click. I need
I have a method that takes an array of queries, and I need to
I need to call a method I have defined as: -(IBAction)next:(id)sender{ ... } I
Hi I have a helper method, which returns a string, where i need to
I have a COM interface and need to add an accessor method to it.
I have use the TryUpdateModel method on the controllers but now I need to
I have a service class that I need to execute a method on a
I need to implement a call to a method that I have in my
I have a use case where I need to call a (non-static) method in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.