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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:14:17+00:00 2026-05-12T05:14:17+00:00

Okay, the title is not saying too much, sorry. Essentially it’s an Architecture Question

  • 0

Okay, the title is not saying too much, sorry. Essentially it’s an Architecture Question about an Application that can have multiple database backends (Well, “Database” is loosely used here as it can mean anything from MSSQL to XML Files to an IList in Memory), essentially involving the Repository Pattern.

I have a set of POCOs that essentially just serve as Data Transfer object (DTOs) and therefore do nothing except carry data. Unfortunately, I am seeing myself in the need to decorate them with Attributes i.e. for use with certain ORMs or even for use with the XmlSerializer. That means that they are now somewhat bound to the database layer and in my opinion not simple POCOs anymore.

From what I see, I would now have to duplicate these DTO-Classes, so that I have one Database-Specific class with Attributes and whatever I need, and a second version that is generic through my application. My Model would then have to convert them (which is where something like AutoMapper could be used)

It just still “feels weird” as I am essentially duplicating all my DTO Classes, yet the existence of Object-To-Object mappers seems to indicate that this is perfectly fine. Also, this seems to copy the ADO.net Approach whereas there is a Generic Part (down to the DataSet) and a Database-Specific part.

Is that correct? Or is there a different approach?

  • 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-12T05:14:17+00:00Added an answer on May 12, 2026 at 5:14 am

    In the (somewhat limited) case of only needing to add Attributes for use with a given ORM, it is possible to write a wrapper that adds these things at runtime. You could add such code to the ORM constructor (subclassing the ORM or ORM initialization class as necessary), or to an ORM-initialization event.

    An example is given below for tagging three properties with an attribute using Reflection, but it could be easily modified to add attributes to a type, or to all properties, etc.

     PropertyDescriptor[] properties = TypeDescriptor.GetProperties(this);
     //Add as necessary
     string[] propertiesToTagForORM = { "Name", "Category", "Description" };
    
     foreach (string propname in propertiesToTagForORM)
            {
                PropertyDescriptor prop = properties[propname];
                if (prop != null)
                {
                    AttributeCollection runtimeAttributes = prop.Attributes;
                    // make a copy of the original attributes 
                    // but make room for one extra attribute
                    Attribute[] attrs = new Attribute[runtimeAttributes.Count + 1];
                    runtimeAttributes.CopyTo(attrs, 0);
                    attrs[runtimeAttributes.Count] = new BrowsableAttribute(false); 
    
                    prop = TypeDescriptor.CreateProperty(this.GetType(), propname, prop.PropertyType, attrs);
                    properties[propname] = prop;
                }
            }
    }
    

    Adapted from here. Just an idea – this is probably the first direction I’d head 🙂

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

Sidebar

Related Questions

Okay that's probably not the best title, I know why we need browser resets:
Okay sorry for the title, wasn't too sure how to phrase it. So we
Sorry about the question title, but I couldn't find a more appropriate way to
Okay the question title may not have made sense... mostly because I don't know
Okay, next PHPExcel question. I have an HTML form that users fill out and
(I'm not sure if that title is worded correctly, as I'm still new to
I had trouble coming up with a title for this question because I'm not
Okay, I'll admit - the title is not the most descriptive/helpful but I couldn't
Okay, the title of this topic is really stupid - but I am not
Okay, the title is a mouthful and I think that's probably why it has

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.