首页 \ 问答 \ Linq2Sql的T-SQL语句(T-SQL Statement with Linq2Sql)

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
更新时间:2021-11-27 21:11

最满意答案

.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 variable gamesCloudItems 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(...)) ...
  • 您需要在回调函数中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 ...
  • 你的代码看起来不错。 我只能说我总是使用自己 functionCall(param) .then( function () { console.log('success'); }, function (sender, args) { console.log('fail'); }); 也许这值得一试? 这可能也是一个有趣的话题: ...
  • 您无法将控制器包装在返回的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 ...
  • 相关文章

    更多
  • JDBC系列教程之四:SQL注入PreparedStatement和Statement
  • sql 语句
  • sql问题
  • Mybatis SQL 语句构建器
  • oracle 的SQL语句问题
  • 不会sql语句....谁帮我优化下
  • Sql Support within Solr-类Sql的solr搜索实现(1)
  • 如何优化这个sql语句
  • Hibernate在那个方法里将HQL转成普通SQL语句并执行的?
  • SQL Server 压力测试
  • 最新问答

    更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)