Angular js应用程序数据绑定无法加入记录

时间:2017-12-16 06:45:45

标签: angular entity-framework linq wcf

我正在将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
    }
} 

这是我运行应用程序并单击带有帐号的提交按钮时的屏幕截图。它应显示帐号1的记录并合并两个表记录,但它也显示记录的其余部分 enter image description here

这是数据库记录,其中我拥有帐号enter image description here

的所有记录

1 个答案:

答案 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
}