Linq2Sql的T-SQL语句(T-SQL Statement with Linq2Sql)
我尝试在Linq2SQL中转换以下SQL Select语句:
SELECT stoptimes.stopid, trips.tripid, stoptimes.sequence FROM trips INNER JOIN stoptimes ON stoptimes.tripid = trips.tripid WHERE ( trips.routeid = '3' ) AND ( trips.endplace = 'END001' ) ORDER BY stoptimes.sequence DESC
它运行良好,但使用linq2sql,我得到以下语句的异常:
var first = (from tableTrip in db.Trips join tableStopTimes in db.StopTimes on tableTrip.TripId equals tableStopTimes.TripId where tableTrip.RouteId == 3 && tableTrip.EndPlace == "TAEND" select new { tableStopTimes.StopId, tableStopTimes.Radius, tableStopTimes.PlaceName, tableStopTimes.Place, tableStopTimes.Sequence }).OrderByDescending(X => X.Sequence).First();
谢谢
I try to convert the following SQL Select statement in Linq2SQL:
SELECT stoptimes.stopid, trips.tripid, stoptimes.sequence FROM trips INNER JOIN stoptimes ON stoptimes.tripid = trips.tripid WHERE ( trips.routeid = '3' ) AND ( trips.endplace = 'END001' ) ORDER BY stoptimes.sequence DESC
It works well but with linq2sql, I get an exception with this following statement:
var first = (from tableTrip in db.Trips join tableStopTimes in db.StopTimes on tableTrip.TripId equals tableStopTimes.TripId where tableTrip.RouteId == 3 && tableTrip.EndPlace == "TAEND" select new { tableStopTimes.StopId, tableStopTimes.Radius, tableStopTimes.PlaceName, tableStopTimes.Place, tableStopTimes.Sequence }).OrderByDescending(X => X.Sequence).First();
Thanks
原文:https://stackoverflow.com/questions/11478144
最满意答案
.then()
期望命名或匿名函数委托作为参数。在下面的代码中......
getGamesCloudOrderBook().then( outputGamesCloudRevenue(gamesCloudItems), function (sender, args) { ... });
...你没有传递函数
outputGamesCloudRevenue
作为第一个参数,你实际上是在执行函数(使用未定义的变量gamesCloudItems
作为参数),然后将执行函数的返回值(如果有的话)传递给.then()
。试试这个:
getGamesCloudOrderBook().then( outputGamesCloudRevenue, function (sender, args) { console.log('An error occurred while retrieving Games Cloud Order Books.') });
.then()
expects named or anonymous function delegates as parameters.In the following piece of code...
getGamesCloudOrderBook().then( outputGamesCloudRevenue(gamesCloudItems), function (sender, args) { ... });
...you're not passing in the function
outputGamesCloudRevenue
as the first parameter, you're actually executing the function (with the undefined variablegamesCloudItems
as its parameter) and then passing the executed function's return value (if any) to.then()
.Try this instead:
getGamesCloudOrderBook().then( outputGamesCloudRevenue, function (sender, args) { console.log('An error occurred while retrieving Games Cloud Order Books.') });
相关问答
更多-
免责声明 :jQuery承诺不会与其他库发挥很好 - 完全一样 。 jQuery不会同意其他第三方的承诺。 另一方面,角度的$ q承诺 - 会,所以只要你有选择,将jQuery承诺融入到Angular承诺中,而不是相反。 (所有这一切都改变了jQuery 3.0,如果你看到这个免责声明和3.0已经发布 - 请留下评论)。 将jQuery承诺转换为Angular承诺: var angularPromise = $q.when(jQueryPromise); // eg: $q.when($.get(...)) ...
-
jQuery推迟:在方法中嵌套承诺,过早回调(jQuery deferred: Nesting promises in methods, last callback too early)[2024-02-13]
您需要在回调函数中return promise。 这是承诺链可以等待他们的唯一方式。 此外,您滥用显式承诺创建反模式。 .then()返回一个承诺。 你可以返回。 将单个承诺传递给$.when()是没有意义的,因为所有$.when()都要做的就是将它吐出来: function first() { $('ul').append("- first started
"); let deferred = $.Deferred(); setTimeout(function() { // ... -
为什么执行链在doDefer()停止,如果它遇到第一个fail函数? 据我所知, then返回一个promise,这是第二个函数如何链接(并执行)。 在第一个链中完成的回调总是重写(?) - 那么为什么jQuery以不同的方式处理failFilter ? 我不确定我是否理解你,但你应该知道两件事: then(done, fail)只执行其中一个回调,具体取决于它们被链接的承诺是满足还是被拒绝。 错误处理在jQuery中完全被破坏了 。 回调确实按预期调用,但.then(…)调用返回的promise不符合Pr ...
-
从SharePoint(加载项)跨域获取承诺的100多个列表项(Get over 100 list items with promise from SharePoint (add-in) cross domain)[2023-12-10]
你的代码看起来不错。 我只能说我总是使用自己 functionCall(param) .then( function () { console.log('success'); }, function (sender, args) { console.log('fail'); }); 也许这值得一试? 这可能也是一个有趣的话题: ... -
使用JQuery延迟的SharePoint 2013中的异步调用(Asynchronous Calls in SharePoint 2013 with JQuery Deferred)[2023-06-16]
您无法将控制器包装在返回的promise中,以下代码不起作用 var myApp = angular.module('myApp', []); deferred.done(function (value) { // Doesn't work <---- myApp.controller("myController", function ($scope) {//Error angularjs can't put inside jquery... var json ... -
$.when( _this.processCookies() ) .then( _this.loadAdScripts() ) .then( _this.createChildViews() ); 似乎是立即调用loadScripts() , createChildViews() ,而是尝试在.then(_this.loadAdScripts)回调函数中引用函数名称。 return def.resolve()返回jQuery.Deferred()对象,而不是jQuery承诺 ...
-
问题是你没有在每个循环中向promises数组推送任何东西 function listing() { var deferred = $.Deferred(); var promises = []; var promise; var index = 0; var list = $('ul').find('li'); list.each(function (index) { var that = $(this); var defer ...
-
你基本上会创建3个延迟对象,每个异步请求一个。 完成异步请求后,您将在延迟对象上调用.resolve方法 // query will return a promise outputPromise = query(); // your third function needs to wait for the promise to resolve // to ensure the wait, you use the .then() method on the promise above outputPromi ...
-
.then()期望命名或匿名函数委托作为参数。 在下面的代码中...... getGamesCloudOrderBook().then( outputGamesCloudRevenue(gamesCloudItems), function (sender, args) { ... }); ...你没有传递函数outputGamesCloudRevenue作为第一个参数,你实际上是在执行函数(使用未定义的变量gamesCloudItems ...
-
首先,确保getSubscriptionTypes实际返回Promise。 没有必要在其中创建自己的$.Deferred - 这样做是一个承诺反模式 : function getSubscriptionTypes(st_id) { return $.ajax({ type: "POST", url: "addUser.php", data: { st_id: st_id }, dataType: "jso ...