我正在尝试将三个linq查询连接到单个查询中,并将记录显示到角度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
join z in context.Current_Account_Details on y.Account_Number equals z.Account_Number
where x.Account_Number == accountNumber
select new
{
x.Account_Number,
x.Amount,
Amount1 = y.Amount,
z.Account_Balance,
}).ToList();
var js = new System.Web.Script.Serialization.JavaScriptSerializer();
return js.Serialize(CombinedQuery); // return JSON string
}
}
有人在此链接上建议我.. http://www.advancesharp.com/blog/1108/linq-inner-join-left-outer-join-on-two-lists-in-c-with-example 这是数据库记录截图:
答案 0 :(得分:1)
可能你可以使用这个类
的概念ReturnClass
{
Current_Account_Details detail {get;set;}
List<Current_Account_Withdraw> listofwithdraw {get;set;}
List<Current_Account_Deposit> listofdeposit {get;set;} }
}
示例:(代码可能无效:D) 我将使用lambda
context.Current_Account_Details.Select(x => new
{
x.Account_Number,
detail = x,
listofwithdraw = x.Current_Account_Withdraw.ToList(),
listofdeposit = x.Current_Account_Deposit.ToList()
}).ToList();