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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:46:09+00:00 2026-05-21T02:46:09+00:00

I want to add metadata to my object graph for non-domain type data that

  • 0

I want to add metadata to my object graph for non-domain type data that will be associated to my objects but is not essential to the problem set of that domain. For example, I need to store sort settings for my objects so that the order in which they appear in the UI is configurable by the user. The sort indices should be serializable so that the objects remember their positions. That’s just one among a few other metadata items I need to persist for my objects. My first thought is to solve this by having a MetadataItem and a MetadataItemCollection where the base Entity class will have a “Meta” property of type MetadataItemCollection. E.g.:

public class MetadataItem
{
    public string Name;
    public object Data;
}

public class MetadataItemCollection
{
    /* All normal collection operations here. */

    // Implementation-specific interesting ones ...
    public object Get(string name);
    public MetadataItem GetItem(string name);

    // Strongly-type getters ...
    public bool GetAsBool(string name);
    public string GetAsString(string name);

    // ... or could be typed via generics ...
    public T Get<T>(string name);
}

public class Entity
{
    public MetadataItemCollection Meta { get; }
}

A few concerns I can think of are:

  • Serialization – the database has a single table of EntityID | Name | Value where Value is a string and all types are serialized to a string?
  • Future Proofing – what if a metadata item’s type (unlikely) or name needs to be changed?
  • Refactorability – should the keys come from a static list via enum or a class with static string properties, or should free-form strings be allowed:
var i = entity.Meta["SortIndex"];

vs.

public enum Metadatas { SortIndex };
var i = entity.Meta[Metadatas.SortIndex];

vs.

public static class Metadatas
{
    public static string SortIndex = "SortIndex";
}
var i = entity.Meta[Metadatas.SortIndex];
  • Anything else?

Thoughts, ideas, gotchas???

Thanks for your time.

Solution:

Following @Mark’s lead, and after watching the Udi video Mark linked to, I created two new interfaces: IUiPresentation and IUiPresentationDataPersistor. It’s important to note that none of the objects in my Entity object model have any awareness of these interfaces; the interfaces are in a separate assembly and never referenced by my Entity object model. The magic is then done via IoC in the presentation models. It would be something like the following:

public class PhoneViewModel
{
    IUiPresentationDataPersistor<Phone> _uiData
    IUiPresentation<Phone> _presenter;

    // Let IoC resolve the dependency via ctor injection.
    public PhoneViewModel(Phone phone, IUiPresentationDataPersistor<Phone> uiData)
    {
        _uiData = uiData;
        _presenter = uiData.Get(phone);  // Does a simple lookup on the phone's ID.
    }

    public int SortIndex
    {
        get { return _presenter.SortIndex; }
        set { _presenter.SortIndex = value; }
    }

    public void Save()
    {
        _uiData.Save();
    }
}

It’s a little more complicated in that the ViewModel implements INotifyPropertyChanged to get all the goodness that it provides, but this should convey the general idea.

  • 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-21T02:46:10+00:00Added an answer on May 21, 2026 at 2:46 am

    Metadata literally means data about data, but what you seem to be asking for is a way to control and change behavior of your objects.

    I think such a concern is much better addressed with a Role Interface – see e.g. Udi Dahan’s talk about Making Roles Explicit. More specifically, the Strategy design pattern is used to define loosely coupled behavior. I’d look for a way to combine those two concepts.

    As we already know from .NET, the use of static, weakly typed attributes severely limits our options for recomposing components, so I wouldn’t go in that direction.

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

Sidebar

Related Questions

Also I want to know how to add meta data while indexing so that
I have a list of string values that I want add to a hashtable
I am creating an application where I want to add metadata about table fields
i want to add a SWF metadata tag to an ActionScript Project in Flash
I want to add my Entity's to my SessionFactory but i don't know the
This is probably not possible, but I have this class: public class Metadata<DataType> where
I want to add debug metadata to my generated llvm IR, which is created
I have dbml with single table users i want add partial class for User
I have a website built with ASP.NET (3.5) and want add some level of
I have numbers in javascript from 01(int) to 09(int) and I want add 1(int)

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.