我们最近从Oracle 10升级到Oracle 11.2.升级后,我开始看到由函数而不是触发器引起的变异表错误(我之前从未遇到过).它是在旧版Oracle中运行的旧代码.
这是一个会导致错误的场景:
create table mutate (
x NUMBER,
y NUMBER
);
insert into mutate (x, y)
values (1,2);
insert into mutate (x, y)
values (3,4);
Run Code Online (Sandbox Code Playgroud)
我创建了两行.现在,我将通过调用此语句来加倍我的行:
insert into mutate (x, y)
select x + 1, y + 1
from mutate;
Run Code Online (Sandbox Code Playgroud)
这对于复制错误并不是绝对必要的,但它有助于我以后的演示.所以表格的内容现在看起来像这样:
X,Y
1,2
3,4
2,3
4,5
Run Code Online (Sandbox Code Playgroud)
一切都很好.现在是有趣的部分:
create or replace function mutate_count
return PLS_INTEGER
is
v_dummy PLS_INTEGER;
begin
select count(*)
into v_dummy
from mutate;
return v_dummy;
end mutate_count;
/
Run Code Online (Sandbox Code Playgroud)
我创建了一个函数来查询我的表并返回一个计数.现在,我将它与INSERT语句结合起来:
insert into mutate (x, y)
select x + …Run Code Online (Sandbox Code Playgroud) 我已经在~/Views/Shared/DisplayTemplatesnamed中创建了一个显示模板ImpactMatrix.cshtml.它接受一个可为空的int并呈现一个二维矩阵,其中突出显示所选的数字:
@model int?
@{
var matrix = ImpactMatrix.GetMatrix();
}
<div class="impactmatrix">
<table>
@for (int i = 0; i < matrix.GetLength(0); i++)
{
<tr>
@for (int j = 0; j < matrix.GetLength(1); j++)
{
var cell = matrix[i, j];
<td data-color="@cell.Color"
class="matrix @(Model == cell.Value ? cell.Color.ToString() : "")">
@cell.Value
</td>
}
</tr>
}
</table>
</div>
Run Code Online (Sandbox Code Playgroud)
它很容易重复使用,效果很好.我可以在我的视图中调用它,如下所示:
@Html.DisplayFor(m=> m.ImpactFactor, "ImpactMatrix")
Run Code Online (Sandbox Code Playgroud)
现在我决定扩展它并使其成为编辑器.我们的想法是为所选数字添加隐藏输入,并使用div将输入与矩阵模板一起包装.从那里开始使用Javascript与我的显示网格交互并填充隐藏的输入应该是一件简单的事情.
我ImpactMatrix.cshtml在我的~/Views/Shared/EditorTemplates文件夹中创建了一个名为的编辑器模板.这是代码:
@model int?
<div class="impactmatrix-editor">
@Html.HiddenFor(m => m)
@Html.DisplayFor(m => m, "ImpactMatrix") …Run Code Online (Sandbox Code Playgroud) 这个让我完全不知所措......
我有一个非常简单的输入模型,有三个字符串属性,如下所示:
public class SystemInputModel
{
public string Name;
public string Performance;
public string Description;
}
Run Code Online (Sandbox Code Playgroud)
在我的控制器中:
public ViewResult AddSystem()
{
return View(new SystemInputModel());
}
[HttpPost]
public ActionResult AddSystem(SystemInputModel model)
{
if (ModelState.IsValid)
{
var system = new OasisSystem
{
Name = model.Name,
Description = model.Description,
Performance = model.Performance
};
return Json(repository.AddSystem(system));
}
return Json(new {success = false, message = "Internal error"});
}
Run Code Online (Sandbox Code Playgroud)
风景:
<h2>Add System</h2>
@using (Html.BeginForm())
{
@Html.ValidationSummary(true)
<label>Name</label>
@Html.EditorFor(m => m.Name)
<br />
<label>Description</label>
@Html.EditorFor(m => m.Description) …Run Code Online (Sandbox Code Playgroud)