Querying the database for information using ASP.NET

I am facing a challenge in my ASP.NET MVC application related to the signup form. I need to verify user-entered data against my database table and retrieve the corresponding Id if there is a match.

The information collected from users includes their email address, surname, and date of birth.

Currently, I am trying to compare these details in the controller to find an existing record Id. However, the query execution time is causing timeouts.

Is there a more efficient way to search for records?

This snippet shows a portion of my Controller code:

public JsonResult SignUpCustomer(string emailAddress, string password, string surName, string name, DateTime dateOfBirth, string timeZone)
{
  // Code implementation here
}

Answer №1

To optimize your Linq query, you can simplify it as shown below:

var loweredName = surName.ToLower();
var loweredEmailAddress = surName.ToLower();
var dateOfBirthDateDatePart = dateOfBirth.Date;
customerID = db.Customer.FirstOrDefault(
                 x => x.Sur_Name.ToLower().Contains(loweredName)
                   && x.Date_of_birth.Year == dateOfBirthDateDatePart.Year
                   && x.Date_of_birth.Month == dateOfBirthDateDatePart.Month 
                   && x.Date_of_birth.Day == dateOfBirthDateDatePart.Day 
                   && x.Email_Primary.ToLower() == loweredEmailAddress)?.Id;

Make sure to update other selects accordingly.

Date comparison methods vary based on the Ef or efCore version being used. For guidance on choosing the most effective approach, refer to this resource.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What are some ways to clear a GridView?

My GridView is presenting search results, but I'm encountering an issue. After executing the first search, everything works perfectly. However, upon clicking the search button a second time and finding no results, the old data is still being displayed ...

Do we need to include href in the anchor tag?

Why am I unable to display the icon within the <anchor> element without using the href attribute? The icon only appears when I set the href attribute to "". Even if I manage to show the icon by adding href="", adjusting the size with width and height ...

Execute a function prior to making a synchronous call

Seeking guidance on a complex issue that I have encountered. In my code, I am dealing with a synchronous AJAX call and need to execute a function before this particular call is made. The function in question is a simple one: $.blockUI(); This function ...

Verification for distinct applications within a shared domain

Similar questions have been asked, but this one is unique to my situation - my apologies if it seems repetitive. I have two applications hosted on the same domain. www.domain.com/site1 www.domain.com/site2 I am attempting to implement forms authenticati ...

Challenge with jQuery - updating closest HTML element not functioning as expected

A script was created to extract the innerHTML of an element with a specific class. Initially, this worked perfectly for the first <table>, but the same script applied to table 1 is affecting the second and third <table> as well. An attempt was ...

The error message appears as "TypeError: json cannot be iterated

Encountering an Issue C:\Development\AlphaLauncher-Recode\app\assets\js\loggerutil.js:29 [Launcher] TypeError: json is not iterable at DistroIndex._resolveInstances (C:\Development\AlphaLauncher-Recode\app& ...

Ant Design's EditableRow feature fails to update the buttons appropriately from "edit" to "save" and "cancel" prompts

Having some trouble with my code while using the Antd library. Can't seem to locate the bug. Here is my EditableTableCell component: import React, {Component} from 'react'; import { Form } from '@ant-design/compatible'; import &ap ...

"Enhancing Collaboration with NextJs Multi-Zones' Unified Header

Currently, I have two applications named admin-shell and delivery-management, both of which are being managed using Multi Zones in NextJs. These applications share a common header with navigation links, but I am encountering difficulties navigating betwee ...

Optimizing JavaScript performance by packaging files with Browserify

Currently, I am utilizing AngularJS for the front end of my project. Initially, I was using Grunt as my build tool but now I am interested in transitioning to npm for this purpose. I came across a useful link that discusses using npm scripts as a build too ...

Experiencing difficulties in accessing complete data from a PowerShell script while using powershell.Invoke() function

I am currently facing an issue where I am unable to retrieve the complete list of VM's hosted on a SCVMM machine. Only around 100-110 VM's are being displayed, whereas there should be more. I am fetching specific properties from this list and sto ...

How to confirm the parent state in Angular's UI router?

In summary, I am seeking a function similar to state.is() that can verify a state with multiple child states from one of those child states? This is the structure I have: Parent 1 Child 1.1 Child 1.2 Child 1.3 Parent 2 Child 2.1 ...

Guide on populating a dropdown menu with values based on the selection of another dropdown menu

Could you please help with a situation involving two dropdown lists, one for country and one for state? I am trying to load states based on the chosen country value. I have set up an AJAX call and triggered the change event for the country dropdown. My m ...

How come the callback in Jquery fadeOut keeps looping repeatedly, and what can I do to stop this from happening?

My approach involves fading out a div box and implementing a callback function as shown below: function closeWindow(windowIdPrefix, speed) { $("#" + windowIdPrefix + "_ViewPanel").fadeOut(speed, function() { resetWindow(windowIdPre ...

The toggle feature is failing to execute upon clicking the button with the onclick handler in JavaScript

const toggleButton = document.getElementById('btn'); setInterval(displayTime,1000); toggleButton.onclick= function toggle() { if (toggleButton.innerHTML=="Light") { document.body.style.backgroundColor ="white"; ...

What is the best way to implement a recursive service call that is triggered automatically at regular intervals?

I came across this code snippet: us.isConnected() .then(function (msg) { er.msg = msg }, function (msg) { er.msg = msg }); $interval(function () { us.isConnected() .then(function (msg) { er.msg = msg }, function (msg) { er.msg = msg }); }, ...

Upon initiating a refresh, the current user object from firebase Auth is found to be

Below is the code snippet from my profile page that works perfectly fine when I redirect from the login method of AuthService: const user = firebase.auth().currentUser; if (user != null) { this.name = user.displayName; this.uid = user.uid; } e ...

I need a counter in my React application that is triggered only once when the page scrolls to a specific element

I've encountered a challenge with a scroll-triggered counter on a specific part of the page. I'm seeking a solution using React or pure JavaScript, as opposed to jQuery. Although I initially implemented it with states and React hooks, I've ...

Is the text in bold format or not detectable in contenteditable mode?

I am currently working on developing a custom text editor using the built-in contenteditable feature in HTML. I am trying to figure out how to determine whether the selected text is bold or not within the editor. This is what my current setup looks like: ...

Ignoring the incremented value in a jQuery function

I have been struggling to resolve this issue for quite some time now, and unfortunately, my lack of proficiency in javascript is hindering me. Here's a jfiddle with an interesting jquery code snippet that I came across: [html] <button id="addPro ...

Verifying whether JValue contains a null value

Why doesn't this code work? I am trying to verify if the JSON contains an integer for the key PurchasedValue. () : public PropertyInfo(Newtonsoft.Json.Linq.JToken jToken) { this.jToken = jToken; int PurchasedValue = (int)(jToken["PurchasedVal ...