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 6004933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:19:56+00:00 2026-05-23T01:19:56+00:00

I have 3 fields: urlName , displayName and active . This is check for

  • 0

I have 3 fields: urlName, displayName and active. This is check for edit record. What I want to do here is to check UrlName is unique in Db, but at the same time, if user has already saved the Url but changed DisplayName and Active then the record should update.

Any one tell me how to solve that.

public bool NothingExceptUrlNameExists(string urlName, string displayName, bool active)
        {
            return (from p in _db.SubMenus
                    where p.UrlName == urlName && (p.DisplayName != displayName || p.DisplayName == displayName) && (p.Active != active || p.Active == active)
                    select p).Any();
        }

updating record like

 TryUpdateModel(existingMenu);
                _menu.Add();

This is what I want to achieve

My other 2 values should be added in Query DisplayName and Active. Suppose “Contact” UrlName already in DB. I am loading values from dropdown returning UrlName=”About”, DisplayName=”About Us”, Active = true. Now editing record. Here are the condition to match.

1 – UrlName=”About”, DisplayName=”About Test”, Active = true –> This should update.

2 – UrlName=”About”, DisplayName=”About Us”, Active = false –> This should update.

3 – UrlName=”About”, DisplayName=”About Test”, Active = false –> This should update.

Important : 4 – UrlName=”newnotexist”, DisplayName=”About test”, Active = false –> This should update UrlName and rest if changed.

5 – UrlName=”Contact”, DisplayName=”About Test”, Active = false –> This should not update and generate error.

I hope you understand what I want to do.

  • 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-05-23T01:19:57+00:00Added an answer on May 23, 2026 at 1:19 am

    Based on the updated question, and if I understand it correctly, I think this solution will work for you.

    var urlNameExists = _sb.Any(x => x.UrlName == urlName && x.Id != currentEditId);
    
    if (urlNameExists)
         throw Exception("A record with that UrlName already exists");
    
    TryUpdateModel(existingMenu);
    _menu.Add();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 structures that have 90% of their fields the same. I want
In my gridview I have fields for inserting a new record in the footer.
I have fields in one class and I want to move them to another
I have fields like password,conform password and gender in my registration page password edit
I have fields in mysql that look like this: constant1 , constant2, variable1, variable2,
I have had the same login form and create_profile form for a long time.
I have 3 tables: table events . In this I have fields such as
I have fields with multiple classes. I want to use one of those classes
In my database we have fields where the data is not readable. I now
In SQL its possible to have fields that cannot contain duplicate data. How is

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.