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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:37:00+00:00 2026-06-04T00:37:00+00:00

I have a database with a table called ‘Roles’, with ‘Id’ and ‘RoleName’ columns.

  • 0

I have a database with a table called ‘Roles’, with ‘Id’ and ‘RoleName’ columns.
These are the rows in the table:

  • GUID1 Administrator
  • GUID2 System
  • GUID3 Technician
  • GUID4 Normal

A user in the ‘User’ table can have several roles to it.
I would like to have LINQ code to check if a specific user has the role ‘Technician’.

This is my code for now :

using (MyDbEntities entities = new MyDbEntities())
{
    User user = entities.Users.Where(u => u.Id == userIdToFetch).Single();

    // Check if user is 'Technician'
    if (user.Roles.Any(role => role.Name == "Technician") == true)
    {
         // user IS technician - do work here
    }
}

My problem is – I don’t want to hard-code the string “Technician” to my code,
because maybe one day the name of the role in the database will change to “Tech”.

I have looked at using ‘Resources’, but that is no good, because changing a string in a resource means recompiling the project.

I do not want to add a section to the configuration file that holds this information,
because it seems to me as over-kill…

Any suggestions ?

  • 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-04T00:37:02+00:00Added an answer on June 4, 2026 at 12:37 am

    I’d use a table where I store all the different roles and associate the ID of the role with the role ID of the user. That way you can change the name of the role as much as you like as long as the role ID stays the same.

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

Sidebar

Related Questions

Say I have a database called Poll and have these two table structures. poll
Ok... I have a database table called employees.. This has columns called ID, Name,
I have a database table called users This table has two columns (that are
I have a database with a table called 'links' with 600 million rows in
I have a mysql database table called character with columns like name, strength, intelligence,
I have a database with a table called shuffledQuestions with 2 columns category_id and
I have a database table called user where I have some columns. One of
I have a database table called Posts which stores all the information regarding an
I have a simple database table called Entries: class CreateEntries < ActiveRecord::Migration def self.up
I have a database table with a column called 'symbol', that is unique via

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.