我正在使用ASP.NET MVC,我有一个存储过程的模型,我使用EF Designer从我现有的数据库创建。在这里,我把我的代码:
public class SpGetClientPhonesController : ApiController
{
ShopEntities2 db = new ShopEntities2();
public string Get()
{
var json = "";
spGetRegister_Result objmodel = new spGetRegister_Result( *HERE I SHOULD SPECIFY THE SP INPUT PARAMETERS*);
}
}
我想使用此模型来检索存储过程返回的数据,但我需要首先指定此存储过程所需的输入参数。我怎么能这样做?
答案 0 :(得分:1)
如果您的模型是从数据库生成的,并且您在其中引用了存储过程。
然后,您使用Entity Framework调用存储过程的方式如下:
function computeLeftPoints() {
var points = _points[_ikIndex];
var distance = points[0].distance;
var lock = points[0].lock;
var angle;
//var i;
var iMod = 0;
if (!lock) iMod = 1;
for (let i = _pActive; i > 1 - iMod; i--) {
points[i - 1].s = angle = Math.slope(points[i - 1], points[i]);
points[i - 1].a = Math.angle(points[i - 2], points[i - 1], points[i]);
points[i - 1].ap = anglePoint(points[i - 1]);
if (i - 1 == 0) {
angle = solve(points[i - 1], points[i], 'left');
}
points[i - 1].x = points[i].x + distance * Math.cos(angle); //Must be rounded unless will cause error in arc
points[i - 1].y = points[i].y + distance * Math.sin(angle);
}
if (lock) {
for (let i = 0; i < _pActive; i++) {
points[i + 1].s = angle = Math.slope(points[i + 1], points[i]);
points[i + 1].a = Math.angle(points[i + 2], points[i + 1], points[i]);
points[i + 1].ap = anglePoint(points[i + 1]);
if (i + 1 == 0) {
angle = solve(points[i + 1], points[i], 'left lock');
}
points[i + 1].x = points[i].x + distance * Math.cos(angle);
points[i + 1].y = points[i].y + distance * Math.sin(angle);
}
}
}
function computeRightPoints() {
var points = _points[_ikIndex];
var distance = points[0].distance;
var lock = points[0].lock;
var angle;
var i;
var iMod = 0;
if (!lock) iMod = 1;
for (i = _pActive; i < points.length - 2 + iMod; i++) {
points[i + 1].s = angle = Math.slope(points[i + 1], points[i]);
points[i + 1].a = Math.angle(points[i + 2], points[i + 1], points[i]);
points[i + 1].ap = anglePoint(points[i + 1]);
if (i + 1 == 0) {
angle = solve(points[i + 1], points[i], 'right');
}
points[i + 1].x = points[i].x + distance * Math.cos(angle);
points[i + 1].y = points[i].y + distance * Math.sin(angle);
}
if (lock) {
for (i = points.length - 1; i > _pActive; i--) {
points[i - 1].s = angle = Math.slope(points[i - 1], points[i]);
points[i - 1].a = Math.angle(points[i - 2], points[i - 1], points[i]);
points[i - 1].ap = anglePoint(points[i - 1]);
if (i - 1 == 0) {
angle = solve(points[i - 1], points[i], 'right lock');
}
points[i - 1].x = points[i].x + distance * Math.cos(angle); //Must be rounded unless will cause error in arc
points[i - 1].y = points[i].y + distance * Math.sin(angle);
}
}
}
function solve(point, delta, LF) {
if (!delta.out || !delta.in) return point.s;
point.s = point.s > Math.radians(delta.in.value) + delta.s
? Math.radians(delta.in.value) + delta.s
: point.s < delta.s - Math.radians(delta.out.value)
? delta.s - Math.radians(delta.out.value)
: point.s;
console.log(point.s);
console.log(delta.s);
console.log('Out: ' + (delta.s - Math.radians(delta.out.value)));
console.log('In: ' + (Math.radians(delta.in.value) + delta.s));
return point.s;// return slope
}
答案 1 :(得分:-1)
我正在挖掘并多问一点,我能够解决这个问题。使用实体框架将存储过程映射到模型时,您必须使用2个概念。使用我的prevoius示例和spGetRegister,当我创建模型时,我有spGetRegister和spGetRegister_Result。 spGetRegister_Result是处理Stored Procedure返回的内容的人,spGetRegister是我必须使用其输入参数调用的内容。这是一个例子:
ObjectResult<spGetRegister_Result> newRecord = new spGetRegister_Result;
newRecord = db.spGetRegister( IdClient:9587, IdSite:94);
从这里你可以在变量newRecord
上得到存储过程的结果行,你可以用它做任何你想做的事。