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

The Archive Base Latest Questions

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

I’m writing a data access layer where I want to return just the data

  • 0

I’m writing a data access layer where I want to return just the data required for each request. Let’s say there is a total of 100 properties that you could retrieve, but a normal request will probably just need two or three of them.

So I’ve added a parameter to the request that specifies the properties you want to return and only this data will be pulled from the DB.

A normal request will return a list of 1,000 – 10,000 rows. My big concern now is how to return them efficiently.

The data will be used “internally” in my .NET-project but may also be serialized to XML and JSON, and therefore I don’t want to have 98 empty properties when in fact there is just 2 of them that are populated with data.

So, what would be the best technique (in case of performance and “overhead size”) to use for creating this model?

Update:
So a property could actually have three states. If it never was asked for, it should somehow be removed, and if it was asked for it should be either null or the actual value.

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

    While I agree that Andrei’s answer is convenient, it can definitely have a performance impact. If your data is flat (and it is, since you are ultimately pulling from a database), then you can have an IEnumerable<IDictionary<string, object>> where each row in the IEnumerable<T> is a IDictionary<string, object> contains the values from the row.

    It’s a more unwieldy to begin with, but it is dynamic; the addition or removal of attributes from the result set will still work.

    It’s also more performant, in that you won’t have (1,000 to 10,000) * N calls to reflection (1,000 to 10,000) rows, times N, the number of attributes on each row (if you have 100 attributes per row, then that’s 100,000 to 1,000,000 calls to Reflection, which will add up). The DynamicDictionary ultimately stores the key/value pairs in a lookup table, but it uses Reflection (optimized through the DLR, but that’s still at it’s core) to get to the lookup table.

    And you do know what the properties are (you said you are using it internally for your project, so you have to know what the properties you want to use are). To that end, you really should be using a strongly-typed data transfer object with properties that are all nullable that represent the values from the database; anything that is null or doesn’t exist in the result set gets set to null. Values that don’t exist in the result set never get set.

    This way, you have no Reflection, you get compile-time type checking (which is very important, using DynamicObject will result in run-time exceptions), and better performance.

    Serialization in XML or JSON is simple with either of these approaches, you simply serialize null values, or don’t serialize the property at all (if using XML, just make sure that your schema supports the elements as being options).

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
i want to parse a xhtml file and display in UITableView. what is the
I am writing an app with both english and french support. The app requests

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.