我正在尝试从技术员表中选择ID,并从AspNetUsers表中选择名称。 sql命令在sql server中有效,但在核心项目查询中返回IQueryable<Technician>
,但Technician表中没有Name列。我该如何解决?
public IQueryable<Technician> GetTechnician()
{
var x = context.Technician .FromSql(@"
select t.id,r.Name from technician t
inner join AspNetUsers r on t.user_id = r.Id
");
return x;
}
答案 0 :(得分:0)
您可以创建一个继承自Technician
并具有Name属性的类:
public class NamedTechnician: Technician
{
public string Name {get; set;}
}
或者您可以只使用匿名返回类型:
context.Technician.Select(x=> new {Id = x.Id, Name = x.AspNetUser.Name, ....});