Database.ExecuteSqlCommand什么意思是int返回?

时间:2017-12-21 16:42:21

标签: entity-framework

我有一个SQL查询,删除表中的一些文件

我使用EF

运行它
var app = angular.module("myApp",[]);

            app.filter('highlight', function($sce) {
                return function(text, phrase) {
                if (phrase) text = text.replace(new RegExp('('+phrase+')', 'gi'),
                '<span class="highlighted">$1</span>')
                return $sce.trustAsHtml(text)
                }
            });

            app.controller("myCtrl", ['$scope', 'highlightFilter', function($scope, highlightFilter){
                $scope.arr = [];
                $scope.append = function(){
                    var x = {};
                    x.data1 = "";
                    x.data2 = "";
                    $scope.arr.push(x); 
                };
            }]);

有时它返回0,另一次返回1或另一个int,通过文档搜索我有这个

<!DOCTYPE html>
<html>
    <head>
        <title>Author's List</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.min.js"></script>
        <link href="https://netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
        <style>
            .highlighted { background: yellow }
        </style>
    </head>
    <body ng-controller="myCtrl" ng-app="myApp">
        <div class="container">
            <div class="btn-group">
                <button ng-click ="append()" type="button" class="btn btn-default">Append</button>
                <input type="text" placeholder="Search" ng-model="search.text">
                <br style="clear: both;"/>
                <ul>
                    <li ng-repeat="x in arr | filter:search.text">
                      <span ng-bind-html="x.data1 | highlight:search.text"></span>
                      <span ng-bind-html="x.data2 | highlight:search.text"></span>
                    </li>
                </ul>
            </div>
            <form name ="myForm" novalidate> 
                <table class="table table-bordered">
                    <tr>
                        <th>data1</th>
                        <th>data2</th>
                    </tr>
                    <tr ng-repeat="x in arr">
                        <td><input ng-model="x.data1" required type="text" class="form-control"></td>
                        <td><input ng-model="x.data2" required type="text" class="form-control"></td>
                    </tr>
                </table>
            </form>
        </div>
           </body>

但究竟什么意思是整数?

如果我的结果不是0,Db会发生错误吗?

1 个答案:

答案 0 :(得分:1)

int res = context.Database.ExecuteSqlCommand(comando);

ExecuteSqlCommand返回受DELETE操作影响的总行数。例如,如果删除2行时删除操作结果,则应返回2

  

如果我的结果不是0,Db会发生错误吗?

不,不要使用返回值来检查某种错误。如果SQL Server中发生错误,则会引发错误,最好使用try/catch块来处理错误。