EF Core 2.1 - 模型支持的查询类型

EF Core 2.1 - Query types support with models

当我使用 DbQuery 时,select 语句查询中的列是否应该与 model/entity 完全匹配?

示例如下:

IEnumerable<UserModel> test =  _context.FewUserColumns.FromSql(@"select id, 
                               last_name, from user where user_id = @userId", 
                               param).ToListAsync();

下面是用户模型。

public class userModel
{
        public int id {get;set;}
        public string first_name { get; set; }
        public string last_name { get; set; }
}

我没有在上面的 select 语句中获取 first_name。因此,我看到以下错误。

处理请求时发生未处理的异常。 InvalidOperationException:'FromSql' 操作的结果中不存在所需的列 'first_name'。

这是预期的吗?我们是否应该始终获取所有列以映射到模型中的所有属性?

我在 msdn 上发布了类似的查询并收到了 Julie Lerman 的回复:

Yes, unfortunately that is a constraint...EF Core expects all of those properties to be available.