【问题标题】:Executing raw sql in entity framework does not return result set在实体框架中执行原始 sql 不返回结果集
【发布时间】:2013-11-01 05:06:57
【问题描述】:

我正在使用以下查询。它返回列表中的 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();

我做错了什么?

【问题讨论】:

    标签: c# asp.net linq entity-framework c#-4.0


    【解决方案1】:

    尝试使 SQL 查询中返回的列与您尝试返回的类中的属性名称相匹配:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-15
      • 2020-09-09
      • 2016-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-08
      相关资源
      最近更新 更多