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

The Archive Base Latest Questions

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

My basic need is to get the datatypes from an anonymous type generated from

  • 0

My basic need is to get the datatypes from an anonymous type generated from a LINQ to SQL query.

I have a piece of code (cleverer than I could write, since I haven’t really delved into reflection) which returns the datatypes from an anonymous types, and works perfectly for the elements marked ‘not nullable’ in the linq2sql properties. So, if I have a string it will return as System.String. However, when the element is nullable I end up with the ‘full name’ of it being:

{Name = “Nullable1" FullName = "System.Nullable1[[System.Decimal, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]”}

All I want to extract is the System.Decimal type in such a case (and in cases of strings or whatever, I’d just want System.String). I’ve looked through the properties and can’t find anything that seems to store this.

    private static Dictionary<string, Type> GetFieldsForType<T>(IEnumerable<T> data)
    {
        object o = data.First();

        var properties = o.GetType().GetProperties();

        return properties.ToDictionary(property => property.Name, property => property.PropertyType);
    }

The LINQ query (which I don’t think really matters here):

var theData = from r in db.tblTestEdits select new { myitem = r.textField, mydecimal = r.decimalField }; 

I found this link that seems to try to address a similar thing.
http://ysgitdiary.blogspot.com/2010/02/blog-post.html

Though it seems to return a “string” of what the type is rather than the actual type, which is what I need. Not sure how to convert such a thing.

Many thanks all.

  • 1 1 Answer
  • 1 View
  • 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-20T10:39:12+00:00Added an answer on May 20, 2026 at 10:39 am
    private static Type GetCoreType(Type type)
    {
        if (type.IsGenericType &&
            type.GetGenericTypeDefinition() == typeof(Nullable<>))
            return Nullable.GetUnderlyingType(type);
        else
            return type;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very basic need to get some data from the database and
I have a basic/simple need to create a pipeline transfer process from one SQL
I need to get basic user data from Facebook using FB.api('/<some_id>/') . This works
I need to get very basic input from an external file in C++. I
I am trying to use some basic SQL functions. I need to get an
I have some basic knowledge about compiling C but need to get a couple
I need to get username and password from HttpServletRequest to process the basic authentication.
Well, I completely get the most basic datatypes of C, like short, int, long,
I need to get basic information about the computer's processor in a WPF application
Greetings all. I need to get some opinions from those outside of my work

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.