我正在使用wcf服務轉換爲角色js web應用程序。我有兩個表。我將兩個表記錄加入單個記錄並在角度js應用程序中顯示記錄。當我有記錄兩個表,它能夠檢索,但如果我只有一個數據庫表記錄,它不同意這種下面的查詢顯示任何東西..聯合運營商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 CombinedQuery = (from x in context.Current_Account_Deposit
join y in context.Current_Account_Withdraw
on x.Account_Number equals y.Account_Number
where x.Account_Number == accountNumber //Modify it
select new
{
x.Account_Number,
x.Account_Holder_Name,
x.Transcation_Type,
x.Amount,
Transcation_Type1 = y.Transcation_Type,
Amount1 = y.Amount,
// put other properties here
}).ToList();
var js = new System.Web.Script.Serialization.JavaScriptSerializer();
return js.Serialize(CombinedQuery); // return JSON string
}
}
}
}
這裏是當我運行應用程序並輸入帳號1時的屏幕截圖,它的表格和它的顯示都有記錄。
這裏是當我輸入賬號15只爲Current_Account_Withdraw表記錄,沒有對Current_Account_Deposit表記錄其不顯示任何內容的截屏。
然後我改變它到這個。
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 DepsoitQuery = (from x in context.Current_Account_Deposit
join y in context.Current_Account_Withdraw
on x.Account_Number equals y.Account_Number
into JoinedList
from y in JoinedList.DefaultIfEmpty()
where x.Account_Number == accountNumber //Modify it
select new
{
x.Account_Number,
x.Account_Holder_Name,
x.Amount,
// put other properties here
}).ToList();
var withdrawQuery = (from y in context.Current_Account_Deposit
join x in context.Current_Account_Withdraw
on y.Account_Number equals x.Account_Number
into JoinedList
from x in JoinedList.DefaultIfEmpty()
where x.Account_Number == accountNumber
select new
{
y.Amount,
}).ToList();
var CombinedQuery = DepsoitQuery.Union(withdrawQuery).ToList();//**error on this line**
var js = new System.Web.Script.Serialization.JavaScriptSerializer();
return js.Serialize(CombinedQuery); // return JSON string
}
}
這是我編譯時得到的錯誤。 '列出<>' 不包含 '聯盟' 的定義和最佳的擴展方法過載 'Queryable.Union <>(IQueryable的<>,IEnumerable的<>)' 需要類型的接收器 '的IQueryable <>'
看看我的第一個查詢,我沒有得到我的預期結果,然後我試着這樣 – Mohammad