更新方法的WCF Odata错误

时间:2016-11-28 11:07:59

标签: c# wcf odata

当我们通过wcf odata更新记录时我们收到错误但是当我们插入记录时它正常工作。请参阅错误消息

<html>
<head>
    <title>Bad Request</title>
</head>
<body bgcolor="white">

        <span><h1>Server Error in '/' Application.<hr width=100% size=1 color=silver></h1>

        <h2> <i>HTTP Error 400 - Bad Request.</i> </h2></span>

        <hr width=100% size=1 color=silver>

        <b>Version Information:</b>&nbsp;ASP.NET Development Server 10.0.0.0

        </font>

</body>

代码如下

string Filter = "ServiceCallID eq " + ticketID + " and day(DateCreated) eq " + day + " and month(DateCreated) eq " + month + " and year(DateCreated) eq " + year;
                        var res = _odataGEntities.ServiceCallResults.AddQueryOption("$filter", Filter).Execute().ToList();

                        if (res != null && res.Count > 0)
                        {
                            _odataGEntities = new OdataGEntities(new Uri(ServieRefLinkGen));
                            TT.DataLayer.GenODataService.ServiceCallResult req = (from r in _odataGEntities.ServiceCallResults
                                                                                       where r.ServiceCallID == ticketID && r.DateCreated.Day == CreatedDate.Day && r.DateCreated.Month == CreatedDate.Month  && r.DateCreated.Year == CreatedDate.Year
                                                                                  select r).First();
                            req.CompletionStatus = Convert.ToInt32(table.Rows[i]["CompletionStatus"]);
                            req.IsExactlyAsQuoted = Convert.ToBoolean(table.Rows[i]["ExactlyAsQuoted"]);
                            req.IsExtraCharges = Convert.ToBoolean(table.Rows[i]["ExtraCharges"]);
                            req.IsPartsMissing = Convert.ToBoolean(table.Rows[i]["PartMissing"]);
                            req.IsWrongParts = Convert.ToBoolean(table.Rows[i]["WrongParts"]);
                            req.IsCustomerDeniedService = Convert.ToBoolean(table.Rows[i]["CustomerDeniedService"]);
                            req.Other = Convert.ToBoolean(table.Rows[i]["OtherReason"]);
                            req.Remarks = Convert.ToString(table.Rows[i]["Remarks"]);
                            req.DateCompleted = Convert.ToString(table.Rows[i]["DateCompleted"]) != String.Empty ? Convert.ToDateTime(table.Rows[i]["DateCompleted"]) : (DateTime?)null;
                            req.SignerName = Convert.ToString(table.Rows[i]["SignerName"]);
                            req.CustomerEmail = Convert.ToString(table.Rows[i]["CustomerEmail"]);
                            req.ModifiedBy = Convert.ToString(table.Rows[i]["ModifiedBy"]);
                            _odataGEntities.UpdateObject(req);
                            _odataGEntities.SaveChanges();
                        }
                        else
                        {
                            _odataGEntities = new OdataGEntities(new Uri(ServieRefLinkGen));
                            TT.DataLayer.GenODataService.ServiceCallResult techData = new TT.DataLayer.GenODataService.ServiceCallResult();

                            techData.ServiceCallID = Convert.ToInt32(table.Rows[i]["TicketID"]);
                            techData.CompletionStatus = Convert.ToInt32(table.Rows[i]["CompletionStatus"]);
                            techData.IsExactlyAsQuoted = Convert.ToBoolean(table.Rows[i]["ExactlyAsQuoted"]);
                            techData.IsExtraCharges = Convert.ToBoolean(table.Rows[i]["ExtraCharges"]);
                            techData.IsPartsMissing = Convert.ToBoolean(table.Rows[i]["PartMissing"]);
                            techData.IsWrongParts = Convert.ToBoolean(table.Rows[i]["WrongParts"]);
                            techData.IsCustomerDeniedService = Convert.ToBoolean(table.Rows[i]["CustomerDeniedService"]);
                            techData.Other = Convert.ToBoolean(table.Rows[i]["OtherReason"]);
                            techData.Remarks = Convert.ToString(table.Rows[i]["Remarks"]);
                            techData.DateCompleted = Convert.ToString(table.Rows[i]["DateCompleted"]) != String.Empty ? Convert.ToDateTime(table.Rows[i]["DateCompleted"]) : (DateTime?)null;
                            techData.DateCreated = Convert.ToDateTime(table.Rows[i]["CreatedDate"]);
                            techData.SignerName = Convert.ToString(table.Rows[i]["SignerName"]);
                            techData.CustomerEmail = Convert.ToString(table.Rows[i]["CustomerEmail"]);
                            techData.CreatedBy = Convert.ToString(table.Rows[i]["ModifiedBy"]);
                            techData.ModifiedBy = Convert.ToString(table.Rows[i]["ModifiedBy"]);
                            _odataGEntities.AddToServiceCallResults(techData);
                            _odataGEntities.SaveChanges();

                        }
                         DeleteUpdateRecordFromTable("update GenWorkResult SET IsCheckedIn=Yes WHERE TicketID = " + ticketID);
                    }
                    catch (Exception ex)
                    {
                        LogFile(ex.ToString());
                    }

数据正在插入,但是当我们更新数据时,我们就会收到错误,如上所述。我们无法确定确切的问题。请帮我找出这个问题。

0 个答案:

没有答案