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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:51:06+00:00 2026-06-10T02:51:06+00:00

Assume a simple blog-like scenario, where posts are stored both by id and a

  • 0

Assume a simple blog-like scenario, where posts are stored both by id and a SEO friendly slug. Is there a way to check that the slug doesn’t already exist during insert? I mean, I could always do something like:

var check = context.Posts.SingleOrDefault(p => p.slug == slug);

if (check != null)
{
    // slug already exists - modify or throw exception
}
else
{
    // save as normal
}

But that seems woefully inelegant to me. I assume there’s a better way, but am unsure of what it would be.

  • 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-10T02:51:07+00:00Added an answer on June 10, 2026 at 2:51 am

    You could just set the UNIQUE CONSTRAINT on the appropriate table in the underlying database.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume that we have simple jQuery code like the following: var $document =
Lets assume a simple Spring MVC Controller that receives the ID of a domain
Assume I have a class that looks like this: class Sample { public string
I have a question. I own a 128mb vps with a simple blog that
I'm trying to make a simple blog with a posts controller route to the
Let's assume a simple and common scenario. I have a User model with an
Here is a simple example: Assume I have a customer table that has a
Assume a simple JPA entity class like this: @Entity(name=TASK) public class Task implements Serializable
Let's assume we have a simple internet socket, and it's going to send 10
This should be a really, really simple one, I would assume. I'm throwing together

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.