从 LightSwitch HTML 应用程序执行存储过程
Execute Stored Procedure from LightSwitch HTML Application
我是 LightSwitch 的新手,因此不熟悉我的 entities and methods.
工具集
我有一个应用程序使用名为 BrattlecubesData
的数据源并包含两个视图:TBG_V_TimeLog_Details
和 TBG_V_TimeLog_Projects
。这两个数据集由 ProjectID 连接起来,用于显示两个不同的浏览屏幕。
My problem is, I want to implement a button on a ViewDetails screen, which deletes the currently selected record from a dimension table (a dimension table which is not included in my application). I want to achieve this via StoredProcedure.
我发现 an MSDN article 详细说明了如何执行此操作,但他们专注于 C# 和 VB 而不是我在 HTML 应用程序中使用的 Javascript .
THIS LINK 提供了将 MSDN C# 代码翻译成 Javascript,但是关于我的数据集声明,我一直遇到重复错误(错误 0x800a138f - JavaScript runtime error: Unable to get property 'ApplicationData' of undefined or null reference
)
然后我决定尝试创建一个 table 的替代技术来执行我的过程,如上面的 MSDN 文章和 also here 中所述。然而,这项技术最终还需要一个按钮,该按钮将我带到 Javascript,我在其中尝试使用导致相同错误的翻译代码。
按照 Eric Erhardt link 的 MSDN 博客中的说明,我有无错误的 C# 代码来调用我的过程,但我再次卡在将 LineItemID 传递给我的 table 的按钮上,并且然后程序被删除。我的按钮 Edit Execute Code
代码如下
myapp.ViewRecordDetails.DeleteRecord_execute = function (screen) {
var dws = screen.TBG_V_TimeLog_Detail.dataWorkspace;
var comment = screen.TBG_V_TimeLog_Detail.selectedItem;
var operation =
dws.ApplicationData.DeleteProjectComment_Operations.addNew();
operation.LineItemID = comment.LineItemID;
dws.ApplicationData.saveChanges();
};
When run this is giving me the same 0x800a138f
error an balking at 'ApplicationData'. My solution does have a dataSource called ApplicationData which has a manually created table called DeleteProjectComment_Operations
.
Again, this button is located on a ViewDetails screen. The ViewDetails has a button which links to an EditDetails screen, and the Editing works as I want.
If I would be better off moving the Delete to my EditDetails screen, I am happy to do that. Or if the solution is to add the dimension table to my solution, please provide guidance on how to restructure my functions or screens
我不知道如何解决我需要访问的实体或如何编辑我的代码以便将 LineItemID 传递给我的程序。
也有人向我建议我可以使用 AJAX 来实现我的目标,如果这是建议的路线,请向我说明如何完成。
提前谢谢你,我希望我已经提供了足够的细节,但很乐意提供更多。
使用下面的执行代码应该可以成功实现Eric Erhardt approach:
myapp.ViewRecordDetails.DeleteRecord_execute = function (screen) {
var dws = myapp.activeDataWorkspace;
var comment = screen.TBG_V_TimeLog_Detail;
var operation = dws.ApplicationData.DeleteProjectComment_Operations.addNew();
operation.LineItemID = comment.LineItemID;
dws.ApplicationData.saveChanges();
};
与您的代码的唯一区别是对 dws 分配的更改来自:
var dws = screen.TBG_V_TimeLog_Detail.dataWorkspace;
至:
var dws = myapp.activeDataWorkspace;
如果您在此修改后仍然遇到问题,我会扩展 saveChanges 调用以报告任何错误,如下所示:
dws.ApplicationData.saveChanges().then(null, function (errors) {
errors.forEach(function (error) {
alert(error.message);
});
});
我是 LightSwitch 的新手,因此不熟悉我的 entities and methods.
工具集我有一个应用程序使用名为 BrattlecubesData
的数据源并包含两个视图:TBG_V_TimeLog_Details
和 TBG_V_TimeLog_Projects
。这两个数据集由 ProjectID 连接起来,用于显示两个不同的浏览屏幕。
My problem is, I want to implement a button on a ViewDetails screen, which deletes the currently selected record from a dimension table (a dimension table which is not included in my application). I want to achieve this via StoredProcedure.
我发现 an MSDN article 详细说明了如何执行此操作,但他们专注于 C# 和 VB 而不是我在 HTML 应用程序中使用的 Javascript .
THIS LINK 提供了将 MSDN C# 代码翻译成 Javascript,但是关于我的数据集声明,我一直遇到重复错误(错误 0x800a138f - JavaScript runtime error: Unable to get property 'ApplicationData' of undefined or null reference
)
然后我决定尝试创建一个 table 的替代技术来执行我的过程,如上面的 MSDN 文章和 also here 中所述。然而,这项技术最终还需要一个按钮,该按钮将我带到 Javascript,我在其中尝试使用导致相同错误的翻译代码。
按照 Eric Erhardt link 的 MSDN 博客中的说明,我有无错误的 C# 代码来调用我的过程,但我再次卡在将 LineItemID 传递给我的 table 的按钮上,并且然后程序被删除。我的按钮 Edit Execute Code
代码如下
myapp.ViewRecordDetails.DeleteRecord_execute = function (screen) {
var dws = screen.TBG_V_TimeLog_Detail.dataWorkspace;
var comment = screen.TBG_V_TimeLog_Detail.selectedItem;
var operation =
dws.ApplicationData.DeleteProjectComment_Operations.addNew();
operation.LineItemID = comment.LineItemID;
dws.ApplicationData.saveChanges();
};
When run this is giving me the same
0x800a138f
error an balking at 'ApplicationData'. My solution does have a dataSource called ApplicationData which has a manually created table calledDeleteProjectComment_Operations
. Again, this button is located on a ViewDetails screen. The ViewDetails has a button which links to an EditDetails screen, and the Editing works as I want.If I would be better off moving the Delete to my EditDetails screen, I am happy to do that. Or if the solution is to add the dimension table to my solution, please provide guidance on how to restructure my functions or screens
我不知道如何解决我需要访问的实体或如何编辑我的代码以便将 LineItemID 传递给我的程序。
也有人向我建议我可以使用 AJAX 来实现我的目标,如果这是建议的路线,请向我说明如何完成。
提前谢谢你,我希望我已经提供了足够的细节,但很乐意提供更多。
使用下面的执行代码应该可以成功实现Eric Erhardt approach:
myapp.ViewRecordDetails.DeleteRecord_execute = function (screen) {
var dws = myapp.activeDataWorkspace;
var comment = screen.TBG_V_TimeLog_Detail;
var operation = dws.ApplicationData.DeleteProjectComment_Operations.addNew();
operation.LineItemID = comment.LineItemID;
dws.ApplicationData.saveChanges();
};
与您的代码的唯一区别是对 dws 分配的更改来自:
var dws = screen.TBG_V_TimeLog_Detail.dataWorkspace;
至:
var dws = myapp.activeDataWorkspace;
如果您在此修改后仍然遇到问题,我会扩展 saveChanges 调用以报告任何错误,如下所示:
dws.ApplicationData.saveChanges().then(null, function (errors) {
errors.forEach(function (error) {
alert(error.message);
});
});