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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:34:05+00:00 2026-05-28T21:34:05+00:00

I have an EntiyFramework project for which i am storing settings in a table.

  • 0

I have an EntiyFramework project for which i am storing settings in a table.

The setting supports different types but ultimately stores the settings in a string, and converts to the specific type (GUID, string, TimeSpan etc).

Everything works, i just would like to check:

  1. Is there any better way to store application settings in the table (I can have multiple companies for which there are different settings for each)?

  2. What if a setting, for example ‘default_reply_type’, type GUID, references another object primary key in the database?

    There might be a few settings like this where other objects are referenced, and this may increase in future.

    I appreciate there is no explicit referential integritary checking in the schema, but i could implement this manually as part of business logic – is this ok or a nasty fudge?

Regards,

Chris

Code is below.

public abstract class Setting
{
    [Key, Column(Order = 0)]
    public string SettingName { get; set; }
    [Key, Column(Order = 1)]
    public Guid CompanyID { get; set; }
    public virtual Company Company { get; set; }

    public string SettingValue { get; set; }
    public string Description { get; set; }

    public virtual void ConvertToType(string value, ref object outvalue)
    {
        outvalue = Convert.ChangeType(value, outvalue.GetType());
    }

    public virtual string ConvertToString(object value, Type type)
    {
        return Convert.ChangeType(value, typeof(string)).ToString();
    }

    public DateTime? UpdatedDateUTC { get; set; }
}

public class StringSetting : Setting
{
    // no need for any overrides as string is base type
}

public class TimeSpanSetting : Setting
{
    public override void ConvertToType(string value, ref object outvalue)
    {
        TimeSpan ts = new TimeSpan(Convert.ToInt64(value));
        outvalue = ts;
    }

    public override string ConvertToString(object value, Type type)
    {
        if(type != typeof(TimeSpan))
            throw new InvalidCastException(); // throw an error!

        return ((TimeSpan)value).Ticks.ToString();
    }
}
  • 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-28T21:34:06+00:00Added an answer on May 28, 2026 at 9:34 pm

    My own advice on this is as follows:

    Represent Guids with the uniqueidentifier type in SQL. Represent TimeSpans with the bigint type in SQL and store ticks.

    If the uniqueidentifier type is used for a non-primary-key column, consider setting the default value for the column to the empty GUID using CONVERT(uniqueidentifier, ‘00000000-0000-0000-0000-000000000000’) rather than allowing NULL values.

    Review the SQL documentation on uniqueidentifier before using it as a primary key. There are some specific caveats to its use that the application and database designers must be aware of. The SQL Server Books Online topic Using uniqueidentifier Data is a good place to start.

    If a uniqueidentifier is used for a primary key consider setting the column default to either NEWSEQUENTIALID() or NEWID(). The former is generally the preferred choice.

    Foreign keys help the SQL optimizer decide some things, so it’s good to have them if possible, but sometimes there’s just no easy way to relate things that way.

    You should try to avoid multi-column primary keys as they can introduce a range of problems, one of which is fragility of the designed schema, and another being that they are more costly to index and search.

    To answer your question 1: One possible way to store setting information that has multiple variants is to store the settings in an xml column. See xml (Transact-SQL). In fact, you can even store objects in the database using an XmlSerializer (see XmlSerializer Class), which makes the content fairly human readable. There are also ways to extract information from xml serialized objects directly in SQL if necessary (See xml Data Type Methods).

    To answer your question 2: It’s possible that you could design xml stored settings in such a way that it doesn’t need the reference. Barring that, be sure that your column containing the Guid is indexed if it’s not a primary key and make sure you thoroughly review the information on uniqueidentifiers that I referenced earlier so that you understand the impacts, performance and otherwise, of choosing to use Guid/uniqueidentifier.

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

Sidebar

Related Questions

I'm working on an asp.net-mvc project. I have an Items table and a Tags
I have a Answer table which has pk_answerid, answertext , fk_questionid, chosenoptions stored as
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Background: We have a project with many modules. We're using EntityFramework 4.2 with FluentAPI
We have ASP.NET MVC2 project with EntityFramework mappings. alt text http://www.freeimagehosting.net/uploads/552e05f607.jpg How to delete
I have a project I am working on that has a Order entity that
I have a project I am working on that has a Order entity that
I have an EntityFramework model which has a boolean field. To make the mapping
Does EF 4.2 Code First have support for enum types? If so, how do
I have looked around but cannot find anything that answered this particular question related

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.