1

I am using the following query. It returns 5 rows in a list but all the elements in the list are null.

public class TempClass
{
    public int SID { get; set; }
    public string SNAME { get; set; }
    public string SAGE { get; set; }
}

var i = _dbContext.Database
                  .SqlQuery<TempClass>("select ID, NAME, AGE from eis_hierarchy")
                  .ToList();

What I am doing wrong?

1 Answer 1

2

Try making the columns returned in the SQL query match the property names in the class you're trying to return:

var i = _dbContext.Database
    .SqlQuery<TempClass>("select ID as SID, NAME as SNAME, AGE as SAGE from eis_hierarchy")
    .ToList();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.