简体   繁体   English

在实体框架中执行原始SQL不会返回结果集

[英]Executing raw sql in entity framework does not return result set

I am using the following query. 我正在使用以下查询。 It returns 5 rows in a list but all the elements in the list are null . 它在列表中返回5行,但列表中的所有元素均为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? 我做错了什么?

Try making the columns returned in the SQL query match the property names in the class you're trying to return: 尝试使SQL查询中返回的列与您要返回的类中的属性名称匹配:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM