我正在使用带有Entity Framework的ASP.NET MVC 4应用程序。
我想有条件地传递空值,假设是否将值传递到#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/make_shared.hpp>
#include <iostream>
namespace KinBody {
struct Link {
struct Geometry {};
std::vector<boost::shared_ptr<Geometry> > GetGeometries() const {
return {};
}
};
}
int main() {
using namespace boost;
using namespace KinBody;
auto link = make_shared<Link>();
auto geometries = boost::copy_range<std::list<Link::Geometry>>(
link->GetGeometries() | adaptors::indirected
);
}
然后它应该只传递DeptID
的值列表,如果传递DeptID
那么它应该全部部门。
我通过检查DeptID = NULL
编写了一个过程并返回了所需的输出(如果DeptID
为DeptID
,则返回所有行。)
但问题是,当我想通过以下实体框架代码传递空值时,它无法正常工作。
null
知道为什么会这样吗?
答案 0 :(得分:3)
如果DeptID
为NULL,则需要将DBNull.Value
传递到SqlParameter
试试这个:
IdleTicketsChecker.Data.Test11Entities objModel = new Data.Test11Entities();
// I'm *assuming* that DeptID is defined as an "int" - if not, adapt as needed
SqlParameter paramDeptId = new SqlParameter("DeptID", SqlDbType.Int);
if (DeptID == null)
paramDeptId.Value = DBType.Null;
else
paramDeptId.Value = DeptID;
List<GeResult_Result> objTicketList = ExecuteCustomStoredProc<GetIdleTicketsByMinutes_Result>("GeResult", "@DeptID", paramDeptId).ToList();