当我需要传递单个参数时,我可以轻松完成,如下所示:
public ProjectsModel GetProjectListBySearch(int projectId)
{
try
{
using (_context = new Exo_ADBEntities())
{
var getdetailprojectlist = _context.Database.SqlQuery<ProjectsModel>("exec dbo.[GetProjectListByID] @ProjectID", new SqlParameter("@ProjectID", projectId)).FirstOrDefault();
return getdetailprojectlist;
}
}
catch (Exception)
{
throw;
}
}
Run Code Online (Sandbox Code Playgroud)
这很好用,但是当我尝试做同样的事情但传递两个参数时我发现语法错误称为无效参数请帮我做这个.使用两个参数时的代码如下
public List<ProjectsModel> GetProjectDetailsBySectorAndSubSector(int sectorid,int subsectorid)
{
try
{
using (_context = new Exo_ADBEntities())
{
var projectbysectorandsubsector = _context.Database.SqlQuery<ProjectsModel>("exec dbo.[GetProjectDetailsBySectorAndSubSector] @sectorId,@subSectorId", new SqlParameter("@sectorId, @subSectorId", sectorid, subsectorid)).ToList();
return projectbysectorandsubsector;
}
}
catch (Exception)
{
throw;
}
}
Run Code Online (Sandbox Code Playgroud)