C# Asp.net web api MVC

C# Asp.net web api MVC,c#,sql,entity-framework,C#,Sql,Entity Framework,我想在此方法中添加另一个查询,即 从产品id=+id的产品中选择产品名称 但它给出了错误,因为列表中有sales\u line表。。如何解决这个问题?有人能帮我吗 public List<sales_line> Get(int id) { using (project_smartEntities entities = new project_smartEntities()) { entities.Configuratio

我想在此方法中添加另一个查询,即

从产品id=+id的产品中选择产品名称

但它给出了错误,因为列表中有sales\u line表。。如何解决这个问题?有人能帮我吗

public List<sales_line> Get(int id)
    {
        using (project_smartEntities entities = new project_smartEntities())
        {
            entities.Configuration.ProxyCreationEnabled = false;
            return entities.sales_lines.SqlQuery("Select * from sales_line where sales_id=" + id).ToList<sales_line>();
        }
    }
公共列表获取(int-id)
{
使用(project\u smartEntities entities=新项目\u smartEntities())
{
entities.Configuration.ProxyCreationEnabled=false;
return entities.sales_line.SqlQuery(“Select*from sales_line where sales_id=“+id”).ToList();
}
}
您可以使用union sql

Select *,'a' as type_select from sales_line
union all
Select *,'b' as type_select from sales_line1

没有足够的信息来回答您的问题。添加更多代码、您收到的错误并更好地解释您的需求我想应用我从销售表中选择*和从产品表中选择产品名称的查询。。问题在列表中,列表中有sales表,因此它会给出错误,因为它没有product表,直到不清楚您是在尝试加入product表,还是在将结果映射到模型时遇到问题。至少编辑您的问题,并显示所涉及的型号(销售线、产品),并将准确的错误消息粘贴到中。它在产品表上给出了意外的代码错误,但未找到此行的bcz ToList();