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

  • Home
  • SEARCH
  • 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 7440351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:50:20+00:00 2026-05-29T10:50:20+00:00

How do I structure the database? I use a repository pattern with entity framework

  • 0

How do I structure the database? I use a repository pattern with entity framework and code-first to code the models.

For example: I want an admin to set a string to be appended to every username.

I was thinking about a key-value table (settings) that has the following columns? SettingsId, Name, Value. With this method, I would need to manually go in, create a record Name:AppendedToUsername, Value:nil. I would then write repository methods specifically for each settings I need. For eg.

public string GetAppenedToUsername()
{
    db.Settings.FirstOrDefault(s => s.Name == "AppendedToUsername").Select(s => s.Value);
}

Is there any better way of designing this database?

  • 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-29T10:50:21+00:00Added an answer on May 29, 2026 at 10:50 am

    It’s a good solution. I only recommend to create a strongly typed class with these settings and use caching for them.

    Cache service:

     public class CacheService
        {
            private ObjectCache Cache
            {
                get { return MemoryCache.Default; }
            }
    
            public object Get(string key)
            {
                return Cache[key];
            }
    
            public void Set(string key, object data, int cacheTime)
            {
                CacheItemPolicy policy = new CacheItemPolicy();
                policy.AbsoluteExpiration = DateTime.Now.AddMinutes(cacheTime);
    
                Cache.Add(new CacheItem(key, data), policy);
            }
    
            public bool IsSet(string key)
            {
                return (Cache[key] != null);
            }
    
            public void Invalidate(string key)
            {
                Cache.Remove(key);
            }
        }
    

    AppSetting:

    public class AppSetting
    {
        public const string StrSettingKey = "StrSetting";
    
        private CacheService CacheService { get; set; }
        private DbContext DbContext { get; set; }
    
        public AppSetting(ICacheService cache, DbContext db)
        {
            CacheService = CacheService;
            DbContext = db;
        }
    
        public string StrSetting
        {
            get
            {
                if (CacheService.IsSet(StrSettingKey))
                {
                    return (string) CacheService.Get(StrSettingKey);
                }
                else
                {
                    var value = DbContext.Settings.Single(s => s.Name == StrSettingKey).Select(s => s.Value);
                    CacheService.Set(StrSettingKey, value, 60); //one hour
                    return value;
                }
    
            }
            set
            {
    
                var item = DbContext.Settings.Single(s => s.Name == StrSettingKey);
                item.Value = value;
                DbContext.SaveChanges();
                CacheService.Set(StrSettingKey, value);
    
            }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use entity Framework 4.2 and MVC 4 I Got this model/Database structure UserInformation
I want to create a database structure that will has good efficiency. Now database
I need connect to Oracle database use jdbc driver. I look on structure URL
A customers ERP solution has (imho) a really ugly database structure. It doesn't use
I'm writing some code to inspect a MySQL database structure, and need information about
I got a lot of one-to-many relationships in my database structure. For example, you
I am trying to structure a database for optimal use. But I have no
My database structure looks something like this: Person Id Name FieldA FieldB Phone Id
When creating a database structure, what are good guidelines to follow or good ways
I have a database structure that has a Person table which contains fields such

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.