我正在将wcf rest服务用于angular js应用程序。我想检索两个表记录并使用帐号合并它。我想连接这两个表属性并将其显示到角度js应用程序中。但问题是当我在输入字段中输入帐号时没有显示预期记录并且未能合并它。
这是界面。
ExitRegion
这是实施。
[OperationContract]
[WebInvoke(Method = "GET",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/TranscationDetails/{Account_Number}")]
string TranscationDetails(string Account_Number);
这是Angular代码。
public string TranscationDetails(string Account_Number)
{
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 ==(y.Account_Number)
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
}
}
的所有记录
答案 0 :(得分:1)
Linq to Entities无法将Convert.ToInt32
识别为IQueryable
。因为Linq to Entities从您的代码构建SQL查询,而Convert.ToInt32
无法转换为查询。所以,你应该改变它;
where x.Account_Number == Convert.ToInt32(y.Account_Number)
到
where x.Account_Number == y.Account_Number
如果y.Account_Number
是字符串类型,我建议您将其转换为SQL Server和EF实体中的整数。
修改; 强>
此外,where子句条件错误。您没有过滤从客户端发布的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
}