2017-12-22 4 views
0

나는 각도 js 응용 프로그램에 wcf rest service를 사용하고 있습니다. 3 개의 테이블 레코드를 하나의 레코드에 결합하여 웹 응용 프로그램에 표시하고 있습니다. 계정 번호가있는 버튼을 클릭하면 계정 번호, 머니 인, 머니 아웃, 날짜 및 계정 잔액 등의 사용자 계정 정보가 반환됩니다. 하지만 Google 크롬 네트워크 탭에서 다음 오류가 발생했습니다.Linq 쿼리 반환 오류

서버에서 요청을 처리하는 동안 오류가 발생했습니다. 예외 메시지는 'HalifaxWCFProject.Transcation.AccountTransaction'형식이 단일 LINQ to Entities 쿼리 내에서 구조적으로 호환되지 않는 두 초기화에 나타납니다. 한 쿼리는 같은 쿼리의 두 위치에서 초기화 될 수 있지만 두 위치 모두에서 동일한 속성이 설정되고 해당 속성이 같은 순서로 설정되는 경우에만 형식이 초기화됩니다. '. 자세한 내용은 서버 로그를 참조하십시오. 예외 스택 추적은 다음과 같습니다.

다음은 클래스입니다.

public class AccountTransaction 
    { 
     public int? Account_Number { get; set; } 

     public decimal? Deposit { get; set; } 

     public decimal? Withdrawal { get; set; } 

     public decimal? Account_Balance { get; set; } 

     public string Date { get; set; } 

    } 

다음은 Linq 쿼리입니다.

public string TranscationDetails(string Account_Number) 
    { 
     var accountNumber = int.Parse(Account_Number);//It could be better to use TryParse 
     using (HalifaxDatabaseEntities context = new HalifaxDatabaseEntities()) 
     { 
       var inOut = context.Current_Account_Deposit.Where(x => x.Account_Number == accountNumber).Select(w => new AccountTransaction 
       { 
        Account_Number = w.Account_Number, 
        Deposit = (decimal?)null, 
        Withdrawal = (decimal?)w.Amount, 
        Date = w.Date 
       }).Concat(context.Current_Account_Withdraw.Where(x => x.Account_Number == accountNumber).Select(d => new AccountTransaction 
       { 
        Account_Number = d.Account_Number, 
        Deposit = (decimal?)d.Amount, 
        Withdrawal = (decimal?)null, 
        Date = d.Date 
       })).OrderBy(r => r.Date) 
       .Concat(context.Current_Account_Details.Where(x => x.Account_Number == accountNumber).Select(e => new AccountTransaction 
       { 
        Account_Number = e.Account_Number, 
        Account_Balance = (decimal?)e.Account_Balance 
       })); 
       var js = new System.Web.Script.Serialization.JavaScriptSerializer(); 
       return js.Serialize(inOut); // return JSON string 
      } 
     } 
    } 
} 

여기 내 각도의 js 코드입니다.

@{ 
    Layout = null; 
} 

<!DOCTYPE html> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title></title> 
</head> 
<body> 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"></script> 
    <script type="text/javascript"> 
     var app = angular.module('MyApp', []) 
     app.controller('MyController', function ($scope, $http, $window) { 
      $scope.IsVisible = false; 
      $scope.Search = function() { 
       var post = $http({ 
        method: "GET", 
        url: "http://localhost:52098/HalifaxIISService.svc/TranscationDetails/" + encodeURIComponent($scope.Account_Number), 
        dataType: 'json', 
        headers: { 
         'Accept': 'application/json, text/javascript, */*; q=0.01', 
         'Content-Type': 'application/json; charset=utf-8' 
        } 
       }); 

       post.then(function (response) { // .success(function(data => .then(function(response 
        var data = response.data; // extract data from resposne 
        $scope.Customers = JSON.parse(data); // eval(data.d) => JSON.parse(data) 
        $scope.IsVisible = true; 
       }, function (err) { 
        $window.alert(err); 
       }); 
      } 
     }); 
    </script> 
    <div ng-app="MyApp" ng-controller="MyController"> 
     Account Number: 
     <input type="text" ng-model="Account_Number" /> 
     <input type="button" value="Submit" ng-click="Search()" /> 
     <hr /> 
     <table style="border: solid 2px Green; padding: 5px;" ng-show="IsVisible"> 
      @*<table cellpadding="0" cellspacing="0">*@ 
      <tr style="height: 30px; background-color: skyblue; color: maroon;"> 
       <th></th> 
       <th> Account Number</th> 
       <th> Money In</th> 
       <th>Date</th> 
       <th> Money Out</th> 
       <th>Date</th> 
       <th>Account Balance</th> 

       <th></th> 
       <th></th> 

      </tr> 
      <tbody ng-repeat="m in Customers"> 
       <tr style="height: 30px; background-color: skyblue; color: maroon;"> 
        <td></td> 
        <td><span>{{m.Account_Number}}</span></td> 
        <td><span>{{m.Deposit| currency:"£"}}</span></td> 
        <td><span>{{m.Date}}</span></td> 

        <td><span>{{m.Withdrawal | currency:"£"}}</span></td> 
        <td><span>{{m.Date}}</span></td> 
        <td><span>{{m.Account_Balance| currency:"£"}}</span></td> 

       </tr> 

      </tbody> 
     </table> 
    </div> 
</body> 
</html> 

여기 여기 모델 인 데이터베이스 enter image description here

입니다. 여기

내가 대신 AccountTransaction 추가 사용 Unionenter image description here

+0

과 동등합니다. 'Concat' 대신'Union'을 사용해 보았습니까? – programtreasures

+0

지난 2 일 동안 귀하의 모든 질문이 동일합니다. ** 문제의 진술이 잘못되었음을 이해하지 못합니다 **. "나는 3 개의 테이블 레코드를 하나의 레코드 **에 합치는 중입니다 ... 계정 번호, Money In, Money Out, * Date * 및 Account Balance와 같은 사용자 계정 정보를 반환해야합니다." 이 계정으로 ** 다른 작업 **에 많은 작업을 할 수 있지만 날짜가있는 레코드가 하나만 필요합니다. 어느 날짜에 많은 작업을 수행해야합니까? 이거 이해 하겠니? 또한,'Concat' 또는'Union'은 ** 행 ** ** 행 **이 아닌 concate입니다. –

+0

"하나의 ** VIEW ** (테이블)에 3 개의 테이블 레코드를 결합"하고 싶지 않을 수 있습니다. "단일 레코드"와 "단일보기"는 ** 완전히 다른 ** ** 것들입니다. –

답변

3

코드 아래에보십시오 응용 프로그램, 추가 된 모든 속성을 실행할 때 다음 enter image description here enter image description here

가 결과입니다 .. 디버깅 모드에서 스크린 샷입니다 Concat

Union은 별개의 값을 반환하지만 여기서 비교는 귀하의 항목을 참조하므로 모든 항목이 다른 것으로 간주됩니다. ConcatUnion All

public string TranscationDetails(string Account_Number) 
    { 
     var accountNumber = int.Parse(Account_Number);//It could be better to use TryParse 
     using (HalifaxDatabaseEntities context = new HalifaxDatabaseEntities()) 
     { 
       var inOut = context.Current_Account_Deposit.Where(x => x.Account_Number == accountNumber).Select(w => new AccountTransaction 
       { 
        Account_Number = w.Account_Number, 
        Account_Balance = (decimal?)0M, 
        Deposit = (decimal?)null, 
        Withdrawal = (decimal?)w.Amount, 
        Date = w.Date 
       }).Union(context.Current_Account_Withdraw.Where(x => x.Account_Number == accountNumber).Select(d => new AccountTransaction 
       { 
        Account_Number = d.Account_Number, 
        Account_Balance = (decimal?)0M, 
        Deposit = (decimal?)d.Amount, 
        Withdrawal = (decimal?)null, 
        Date = d.Date 
       })).OrderBy(r => r.Date) 
       .Union(context.Current_Account_Details.Where(x => x.Account_Number == accountNumber).Select(e => new AccountTransaction 
       { 
        Account_Number = e.Account_Number, 
        Account_Balance = (decimal?)e.Account_Balance, 
        Deposit = (decimal?)0M, 
        Withdrawal = (decimal?)0M, 
        Date = DateTime.Now 
       })); 
       var js = new System.Web.Script.Serialization.JavaScriptSerializer(); 
       return js.Serialize(inOut); // return JSON string 
      } 
     } 
    } 
} 
+0

코드를 사용해 보셨습니까? – programtreasures

+0

대단히 감사합니다. 훌륭하고 큰 도움 @ programtreasures – Mohammad

+0

은 0M을 사용하는 목적을 설명 할 수 있습니다. – Mohammad