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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:02:12+00:00 2026-06-04T15:02:12+00:00

I have a class that looks like this: public class Analyst { [Column(Internal_ID)] public

  • 0

I have a class that looks like this:

public class Analyst
{
    [Column("Internal_ID")]
    public int ID { get; set; } // if this is named like the column, it works
    [Column("DisplayName")]
    public string Name { get; set; }
}

This object is being filled like so (this next part is in a class which inherits from DbContext):

public List<T> ExecProc<T>(string proc, Dictionary<string, object> params)
{
        var parms = new List<SqlParameter>();
        var sql = new StringBuilder();
        sql.Append(sproc.StoredProcedure);
        sql.Append(" "); //  a space, that's all it is
        foreach (var key in sproc.Parameters.Keys)
        {
            sql.Append(string.Format("{0},", key));
            parms.Add(new SqlParameter(key, sproc.Parameters[key]));
        }
        if (sql[sql.Length - 1] == ',') // removing the trailing ,
        {
            sql.Remove(sql.Length - 1, 1);
        }
        return Database.SqlQuery<T>(sql.ToString(), parms.ToArray()).ToList();
}

The returned List contains the correct amount of rows (or objects in this case), but none of the properties are populated with values. If the proc returns 200 rows, then I get 200 objects in the List, but none of them have any values populated.

I have verified that there is no mismatch between the field names and the values in the [Column(“name”)] attribute. If i change the property names to match the field names in the result set, then it works fine, but I cannot seem to get it to work if I try mapping them using the Data Annotations. Can anyone please point out what I’m missing here? I’m certain that it’s something simple.

Using: Visual Studio 2010 Ultimate SP1, .Net 4 SP1, EF 4.2.0 (I encountered the same problem with EF 4.3). This is all done using code only, no mapping files are used for this.

  • 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-06-04T15:02:13+00:00Added an answer on June 4, 2026 at 3:02 pm

    As it seems, this is documented behavior. Database.SqlQuery Method has no direct connection to DbContext model configuration.

    Creates a raw SQL query that will return elements of the given generic
    type. The type can be any type that has properties that match the
    names of the columns returned from the query
    , or can be a simple
    primitive type.

    So, when using this method, you should construct your sql so that result set column names match property names of type used.

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

Sidebar

Related Questions

I have a class that looks like this: public class TaughtSubject { public int
I have a Java class that looks like this: public class My_ABC { int
I have a class that looks like this: public class MyModel{ public int TheId
I have a class that looks like this: public class BasePadWI { public WorkItem
Currently I have a class that looks like this: public class MyClass : IMyClass
I have a class that roughly looks like this: public class ViewModel { public
Assume I have a class that looks like this: class Sample { public string
I have a Handler class that looks like this: class Handler{ public $group; public
I have a program that looks something like this: public partial class It {
I have a model that looks something like this: public abstract class Parent {

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.