iSeller Commerce
iSeller POS Retail
iSeller POS F&B
iSeller POS Express
Crosslight
WebUI
ClientUI
What's New
Download Trial
Web Solution
Mobile Solution
Enterprise Solution
Custom Development
Blog
Community
Latest Development Blogs
ForumPostTopic
Browse By Tag
I have a WebGrid, enabled batch update, client side binding using werbserive.
The reading works perfect and really fast.
My issue is with the write functionality, it always display an error which I really can't figure out!
I checked everything, all looks ok, so please help me on this!
The data context code was auto generated, so no mistake on that.
So this is the WebSerive update function:
WebMethod][GenerateScriptType(typeof(MembershipCheque))]public TransactionResult BatchUpdateMembershipCheques(List<ClientRowChanges> changes) { MembershipDataContext context = new MembershipDataContext(); WebGridDataProvider<MembershipCheque> provider = new WebGridDataProvider<MembershipCheque>(context.MembershipCheques.AsQueryable()); return provider.BatchUpdate(changes); }
This is the error I got:
{"Message":"Operation is not valid due to the current state of the object.","StackTrace":" at System.Web.Script.Serialization.ObjectConverter.ConvertDictionaryToObject(IDictionary`2 dictionary, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToType(Object o, Type type, JavaScriptSerializer serializer)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeList(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}
Based on my research, the error could occur if the changes parameter row structure and the WebGridDataProvider table row structure does not match. You could also provide a more detailed code, the select operation and the WebGrid setting you are using, so I could analyse the issue further.
Hi,
--------------------------------------------------
This is the select function:
[WebMethod] public object GetMembershipTransactions(DataSourceSelectArguments selectArguments) { MembershipDataContext context = new MembershipDataContext(); context.DeferredLoadingEnabled = false; context.ObjectTrackingEnabled = false; int nMembershipID = 0; Int32.TryParse(selectArguments.FilterExpression, out nMembershipID); var MembershipTransactions = from membershipTransaction in context.MembershipTransactions where membershipTransaction.MembershipID == nMembershipID select new { MembershipTransactionID = membershipTransaction.MembershipTransactionID, Amount = membershipTransaction.Amount, MembershipID = membershipTransaction.MembershipID, Note = membershipTransaction.Note, ProcessDate = membershipTransaction.ProcessDate, Processed = membershipTransaction.Processed, ReferenceNo = membershipTransaction.ReferenceNo, TransactionDate = membershipTransaction.TransactionDate, ChequeNo = GetChequeNo(membershipTransaction.MembershipChequeID), CreditCardNo = GetCreditCardInfo(membershipTransaction.CreditCardID) }; return MembershipTransactions.ToList(); throw new InvalidOperationException("Unsupported operation type!"); }
-----------------------------------------------------
And this is the grid configuration:
<ISWebGrid:WebGrid ID="TransactionsWebGrid" runat="server" DefaultStyleMode="Win7" Height="322px" UseDefaultStyle="True" Width="99%" BindingOperationMode="ClientBinding"> <LayoutSettings AllowColumnSizing="No" AllowContextMenu="False" AllowEdit="Yes" AllowSorting="Yes" AlwaysShowHelpButton="True" ColumnSetHeaders="Default" EditOnClick="True" FilterBarVisible="False" InProgressUIBehavior="ChangeCursorToHourGlass" RowHeaders="Default" ShowRefreshButton="False" AllowBatchUpdate="True" NewRowLostFocusAction="AlwaysUpdate" > <BatchUpdateSettings AllowReviewChanges="True" /> <ClientSideEvents OnBatchUpdateSuccess="TransactionsWebGrid_OnBatchUpdateSuccess" /> </LayoutSettings> <RootTable Caption="MembershipTransactions" DataKeyField="MembershipTransactionID" > <Columns> <ISWebGrid:WebGridColumn Caption="Date" DataMember="TransactionDate" EditType="NoEdit" Name="TransactionDate" Width="70px" DataFormatString="d" DataType="System.DateTime"> <HeaderStyle Cursor="Hand" Font-Italic="True" Font-Underline="True" HorizontalAlign="Center" /> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="Amount" DataMember="Amount" Name="Amount" EditType="NoEdit" Width="55px" DataType="System.Decimal"> <HeaderStyle Cursor="Hand" Font-Italic="True" Font-Underline="True" HorizontalAlign="Center" /> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="Cheque No" DataMember="ChequeNo" Name="ChequeNo" EditType="NoEdit" Width="125px" DataType="System.Decimal"> <HeaderStyle Cursor="Hand" Font-Italic="True" Font-Underline="True" HorizontalAlign="Center" /> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="Credit-Card No" DataMember="CreditCardNo" Name="CreditCardNo" EditType="NoEdit" Width="125px" DataType="System.Decimal"> <HeaderStyle Cursor="Hand" Font-Italic="True" Font-Underline="True" HorizontalAlign="Center" /> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="Processed" ColumnType="CheckBox" DataMember="Processed" DataType="System.Boolean" EditType="Checkbox" Name="Processed" Width="60px"> <HeaderStyle Cursor="Hand" Font-Italic="True" Font-Underline="True" HorizontalAlign="Center" /> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="Process Date" CustomEditorName="VistaCalendar" DataFormatString="d" DataMember="ProcessDate" DataType="System.DateTime" EditType="Custom" Name="ProcessDate" Width="70px"> <HeaderStyle Cursor="Hand" Font-Italic="True" Font-Underline="True" HorizontalAlign="Center" /> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="Reference" Name="ReferenceNo" Width="80px" DataMember="ReferenceNo"> <HeaderStyle Cursor="Hand" Font-Italic="True" Font-Underline="True" HorizontalAlign="Center" /> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="Note" DataMember="Note" Name="Note" Width="95px"> <HeaderStyle Cursor="Hand" Font-Italic="True" Font-Underline="True" HorizontalAlign="Center" /> </ISWebGrid:WebGridColumn> </Columns> </RootTable> <ClientBindingSettings DataSourceType="WebService" ServiceUrl="../MembershipDataService.asmx" ItemTypeName="MembershipTransaction" DataLoadMode="AllData"> <ServiceMethods SelectMethod="GetMembershipTransactions" BatchUpdateMethod="BatchUpdateMembershipTransactions" /> <ServiceEvents Selecting="Selecting_MembershipTransactions"/> </ClientBindingSettings> </ISWebGrid:WebGrid>
And this is the table code:
---------------------------------------------------
[Table(Name="dbo.MembershipTransaction")] public partial class MembershipTransaction : INotifyPropertyChanging, INotifyPropertyChanged { private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty); private int _MembershipTransactionID; private System.Nullable<int> _MembershipID; private System.Nullable<int> _TransactionTypeID; private System.Nullable<int> _CreditCardID; private System.Nullable<int> _MembershipChequeID; private System.Nullable<bool> _Processed; private System.Nullable<System.DateTime> _ProcessDate; private System.DateTime _TransactionDate; private System.Nullable<decimal> _Amount; private string _ReferenceNo; private string _Note; #region Extensibility Method Definitions partial void OnLoaded(); partial void OnValidate(System.Data.Linq.ChangeAction action); partial void OnCreated(); partial void OnMembershipTransactionIDChanging(int value); partial void OnMembershipTransactionIDChanged(); partial void OnMembershipIDChanging(System.Nullable<int> value); partial void OnMembershipIDChanged(); partial void OnTransactionTypeIDChanging(System.Nullable<int> value); partial void OnTransactionTypeIDChanged(); partial void OnCreditCardIDChanging(System.Nullable<int> value); partial void OnCreditCardIDChanged(); partial void OnMembershipChequeIDChanging(System.Nullable<int> value); partial void OnMembershipChequeIDChanged(); partial void OnProcessedChanging(System.Nullable<bool> value); partial void OnProcessedChanged(); partial void OnProcessDateChanging(System.Nullable<System.DateTime> value); partial void OnProcessDateChanged(); partial void OnTransactionDateChanging(System.DateTime value); partial void OnTransactionDateChanged(); partial void OnAmountChanging(System.Nullable<decimal> value); partial void OnAmountChanged(); partial void OnReferenceNoChanging(string value); partial void OnReferenceNoChanged(); partial void OnNoteChanging(string value); partial void OnNoteChanged(); #endregion public MembershipTransaction() { OnCreated(); } [Column(Storage="_MembershipTransactionID", DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)] public int MembershipTransactionID { get { return this._MembershipTransactionID; } set { if ((this._MembershipTransactionID != value)) { this.OnMembershipTransactionIDChanging(value); this.SendPropertyChanging(); this._MembershipTransactionID = value; this.SendPropertyChanged("MembershipTransactionID"); this.OnMembershipTransactionIDChanged(); } } } [Column(Storage="_MembershipID", DbType="Int")] public System.Nullable<int> MembershipID { get { return this._MembershipID; } set { if ((this._MembershipID != value)) { this.OnMembershipIDChanging(value); this.SendPropertyChanging(); this._MembershipID = value; this.SendPropertyChanged("MembershipID"); this.OnMembershipIDChanged(); } } } [Column(Storage="_TransactionTypeID", DbType="Int")] public System.Nullable<int> TransactionTypeID { get { return this._TransactionTypeID; } set { if ((this._TransactionTypeID != value)) { this.OnTransactionTypeIDChanging(value); this.SendPropertyChanging(); this._TransactionTypeID = value; this.SendPropertyChanged("TransactionTypeID"); this.OnTransactionTypeIDChanged(); } } } [Column(Storage="_CreditCardID", DbType="Int")] public System.Nullable<int> CreditCardID { get { return this._CreditCardID; } set { if ((this._CreditCardID != value)) { this.OnCreditCardIDChanging(value); this.SendPropertyChanging(); this._CreditCardID = value; this.SendPropertyChanged("CreditCardID"); this.OnCreditCardIDChanged(); } } } [Column(Storage="_MembershipChequeID", DbType="Int")] public System.Nullable<int> MembershipChequeID { get { return this._MembershipChequeID; } set { if ((this._MembershipChequeID != value)) { this.OnMembershipChequeIDChanging(value); this.SendPropertyChanging(); this._MembershipChequeID = value; this.SendPropertyChanged("MembershipChequeID"); this.OnMembershipChequeIDChanged(); } } } [Column(Storage="_Processed", DbType="Bit")] public System.Nullable<bool> Processed { get { return this._Processed; } set { if ((this._Processed != value)) { this.OnProcessedChanging(value); this.SendPropertyChanging(); this._Processed = value; this.SendPropertyChanged("Processed"); this.OnProcessedChanged(); } } } [Column(Storage="_ProcessDate", DbType="DateTime")] public System.Nullable<System.DateTime> ProcessDate { get { return this._ProcessDate; } set { if ((this._ProcessDate != value)) { this.OnProcessDateChanging(value); this.SendPropertyChanging(); this._ProcessDate = value; this.SendPropertyChanged("ProcessDate"); this.OnProcessDateChanged(); } } } [Column(Storage="_TransactionDate", DbType="DateTime NOT NULL")] public System.DateTime TransactionDate { get { return this._TransactionDate; } set { if ((this._TransactionDate != value)) { this.OnTransactionDateChanging(value); this.SendPropertyChanging(); this._TransactionDate = value; this.SendPropertyChanged("TransactionDate"); this.OnTransactionDateChanged(); } } } [Column(Storage="_Amount", DbType="Decimal(18,2)")] public System.Nullable<decimal> Amount { get { return this._Amount; } set { if ((this._Amount != value)) { this.OnAmountChanging(value); this.SendPropertyChanging(); this._Amount = value; this.SendPropertyChanged("Amount"); this.OnAmountChanged(); } } } [Column(Storage="_ReferenceNo", DbType="VarChar(50)")] public string ReferenceNo { get { return this._ReferenceNo; } set { if ((this._ReferenceNo != value)) { this.OnReferenceNoChanging(value); this.SendPropertyChanging(); this._ReferenceNo = value; this.SendPropertyChanged("ReferenceNo"); this.OnReferenceNoChanged(); } } } [Column(Storage="_Note", DbType="VarChar(250)")] public string Note { get { return this._Note; } set { if ((this._Note != value)) { this.OnNoteChanging(value); this.SendPropertyChanging(); this._Note = value; this.SendPropertyChanged("Note"); this.OnNoteChanged(); } } } public event PropertyChangingEventHandler PropertyChanging; public event PropertyChangedEventHandler PropertyChanged; protected virtual void SendPropertyChanging() { if ((this.PropertyChanging != null)) { this.PropertyChanging(this, emptyChangingEventArgs); } } protected virtual void SendPropertyChanged(String propertyName) { if ((this.PropertyChanged != null)) { this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } }
--------------------------------------------------------
Thanks,
Maged
And this is different case with the same error:
--------------
Select function:
---------------
[WebMethod] public object GetMembershipCheques(DataSourceSelectArguments selectArguments) { MembershipDataContext context = new MembershipDataContext(); context.DeferredLoadingEnabled = false; WebGridDataProvider<MembershipCheque> provider = new WebGridDataProvider<MembershipCheque>(context.MembershipCheques.AsQueryable()); object data = provider.Select(selectArguments); if (data != null) return data; throw new InvalidOperationException("Unsupported operation type!"); }
------------------------
Table code:
-------------------------
[Table(Name="dbo.MembershipCheque")] public partial class MembershipCheque : INotifyPropertyChanging, INotifyPropertyChanged { private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty); private int _MembershipChequeID; private System.Nullable<int> _MembershipID; private System.Nullable<System.DateTime> _ChequeDate; private System.Nullable<System.DateTime> _DueDate; private System.Nullable<System.DateTime> _DepositDate; private string _ChequeNo; private string _BatchNo; #region Extensibility Method Definitions partial void OnLoaded(); partial void OnValidate(System.Data.Linq.ChangeAction action); partial void OnCreated(); partial void OnMembershipChequeIDChanging(int value); partial void OnMembershipChequeIDChanged(); partial void OnMembershipIDChanging(System.Nullable<int> value); partial void OnMembershipIDChanged(); partial void OnChequeDateChanging(System.Nullable<System.DateTime> value); partial void OnChequeDateChanged(); partial void OnDueDateChanging(System.Nullable<System.DateTime> value); partial void OnDueDateChanged(); partial void OnDepositDateChanging(System.Nullable<System.DateTime> value); partial void OnDepositDateChanged(); partial void OnChequeNoChanging(string value); partial void OnChequeNoChanged(); partial void OnBatchNoChanging(string value); partial void OnBatchNoChanged(); #endregion public MembershipCheque() { OnCreated(); } [Column(Storage="_MembershipChequeID", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)] public int MembershipChequeID { get { return this._MembershipChequeID; } set { if ((this._MembershipChequeID != value)) { this.OnMembershipChequeIDChanging(value); this.SendPropertyChanging(); this._MembershipChequeID = value; this.SendPropertyChanged("MembershipChequeID"); this.OnMembershipChequeIDChanged(); } } } [Column(Storage="_MembershipID", DbType="Int")] public System.Nullable<int> MembershipID { get { return this._MembershipID; } set { if ((this._MembershipID != value)) { this.OnMembershipIDChanging(value); this.SendPropertyChanging(); this._MembershipID = value; this.SendPropertyChanged("MembershipID"); this.OnMembershipIDChanged(); } } } [Column(Storage="_ChequeDate", DbType="DateTime")] public System.Nullable<System.DateTime> ChequeDate { get { return this._ChequeDate; } set { if ((this._ChequeDate != value)) { this.OnChequeDateChanging(value); this.SendPropertyChanging(); this._ChequeDate = value; this.SendPropertyChanged("ChequeDate"); this.OnChequeDateChanged(); } } } [Column(Storage="_DueDate", DbType="DateTime")] public System.Nullable<System.DateTime> DueDate { get { return this._DueDate; } set { if ((this._DueDate != value)) { this.OnDueDateChanging(value); this.SendPropertyChanging(); this._DueDate = value; this.SendPropertyChanged("DueDate"); this.OnDueDateChanged(); } } } [Column(Storage="_DepositDate", DbType="DateTime")] public System.Nullable<System.DateTime> DepositDate { get { return this._DepositDate; } set { if ((this._DepositDate != value)) { this.OnDepositDateChanging(value); this.SendPropertyChanging(); this._DepositDate = value; this.SendPropertyChanged("DepositDate"); this.OnDepositDateChanged(); } } } [Column(Storage="_ChequeNo", DbType="VarChar(50)")] public string ChequeNo { get { return this._ChequeNo; } set { if ((this._ChequeNo != value)) { this.OnChequeNoChanging(value); this.SendPropertyChanging(); this._ChequeNo = value; this.SendPropertyChanged("ChequeNo"); this.OnChequeNoChanged(); } } } [Column(Storage="_BatchNo", DbType="VarChar(50)")] public string BatchNo { get { return this._BatchNo; } set { if ((this._BatchNo != value)) { this.OnBatchNoChanging(value); this.SendPropertyChanging(); this._BatchNo = value; this.SendPropertyChanged("BatchNo"); this.OnBatchNoChanged(); } } } public event PropertyChangingEventHandler PropertyChanging; public event PropertyChangedEventHandler PropertyChanged; protected virtual void SendPropertyChanging() { if ((this.PropertyChanging != null)) { this.PropertyChanging(this, emptyChangingEventArgs); } } protected virtual void SendPropertyChanged(String propertyName) { if ((this.PropertyChanged != null)) { this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } }
-------------------------------------
Grid config
------------------------------------
<ISWebGrid:WebGrid ID="MembershipChequesGrid" runat="server" DefaultStyleMode="Win7" Height="322px" UseDefaultStyle="True" Width="99%" BindingOperationMode="ClientBinding"> <LayoutSettings AllowColumnSizing="No" AllowContextMenu="False" AllowEdit="Yes" AllowSorting="Yes" AlwaysShowHelpButton="False" ColumnSetHeaders="Default" EditOnClick="True" FilterBarVisible="False" InProgressUIBehavior="ChangeCursorToHourGlass" RowHeaders="Default" ShowRefreshButton="False" AllowBatchUpdate="True" NewRowLostFocusAction="AlwaysUpdate" > <BatchUpdateSettings AllowReviewChanges="True" /> <ClientSideEvents OnBatchUpdateSuccess="TransactionsWebGrid_OnBatchUpdateSuccess" /> </LayoutSettings> <RootTable Caption="MembershipCheques" DataKeyField="MembershipChequeID"> <Columns> <ISWebGrid:WebGridColumn Caption="Due Date" DataMember="DueDate" EditType="Custom" Name="DueDate" Width="80px" DataFormatString="d" DataType="System.DateTime" CustomEditorName="VistaCalendar"> <HeaderStyle Cursor="Hand" Font-Italic="True" Font-Underline="True" HorizontalAlign="Center" /> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="Cheque No" DataMember="ChequeNo" Name="ChequeNo" Width="260px" DataType="System.String"> <HeaderStyle Cursor="Hand" Font-Italic="True" Font-Underline="True" HorizontalAlign="Center" /> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="Batch No" DataMember="BatchNo" Name="BatchNo" Width="250px" DataType="System.String"> <HeaderStyle Cursor="Hand" Font-Italic="True" Font-Underline="True" HorizontalAlign="Center" /> </ISWebGrid:WebGridColumn> <ISWebGrid:WebGridColumn Caption="Deposit Date" DataMember="DepositDate" EditType="Custom" Name="DepositDate" Width="90px" DataFormatString="d" DataType="System.DateTime" CustomEditorName="VistaCalendar"> <HeaderStyle Cursor="Hand" Font-Italic="True" Font-Underline="True" HorizontalAlign="Center" /> </ISWebGrid:WebGridColumn> </Columns> </RootTable> <ClientBindingSettings DataSourceType="WebService" ServiceUrl="../MembershipDataService.asmx" ItemTypeName="MembershipCheque" DataLoadMode="AllData"> <ServiceMethods SelectMethod="GetMembershipCheques" BatchUpdateMethod="BatchUpdateMembershipCheques" /> <ServiceEvents Selecting="Selecting_MembershipCheques"/> </ClientBindingSettings> </ISWebGrid:WebGrid>
I have the same error. I am attaching a stand alone example.
Glenn - Can you take a look?
Thanks,Dave
Attached is another stand alone example.
This one should work
The zip file corupted, can you please resend and summarize the fix for us?
Have you trind manually updating the database instead of using WebGridDataProvider? After a successful operation, you will need to return TransactionResult object as detaild in the article "Transaction Operations (Insert, Update and Delete)" in the WebGrid documentation.
Here is the update snippet for a composite table, exception handling is not implemented:
[WebMethod][GenerateScriptType(typeof(BugCustom))]public TransactionResult UpdateBugsCustom(List<ClientRowChanges> changes){ BugTrackerEntities context = new BugTrackerEntities(); BugTrackerModel.Bug bSingle = null; BugTrackerModel.Owner oSingle = null; foreach(ClientRowChanges change in changes) { BugCustom currRow = (BugCustom)change.NewObject; bSingle = context.Bugs.SingleOrDefault(b => b.BugId == currRow.BugId); bSingle.Summary = currRow.Summary; oSingle = context.Owners.SingleOrDefault(o => o.OwnerID == currRow.OwnerID); oSingle.OwnerName = currRow.OwnerName; } int saveResult = context.SaveChanges(); return new TransactionResult(){ AffectedResults = saveResult, OperationType = DataSourceOperation.BatchUpdate, ReturnValue = true };}
That will not work, as the error is generated before we reach the update function it self, so I believe any change in the update function itself will not help, as the error still happening before we go there!
Glenn,
Were you able to recreate my error using the sample I provided?
The error is a JavaScript error. The request never gets fired to the Web Service. Here is the error:
{"Message":"Operation is not valid due to the current state of the object.","StackTrace":" at System.Web.Script.Serialization.ObjectConverter.ConvertDictionaryToObject(IDictionary`2 dictionary, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeList(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeDictionary(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.DeserializeInternal(Int32 depth)\r\n at System.Web.Script.Serialization.JavaScriptObjectDeserializer.BasicDeserialize(String input, Int32 depthLimit, JavaScriptSerializer serializer)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}
Okay, fixed ......
So there is always work around to fix errors.
But I believe you guys at Intersoft need to do something to fix this issue from your side instead of the work around that I implemented!
So here is the fix:
1- My grid doesn't have all the fields from the table, as I don't need to display them all.
2- I have another fields from different tables displayed on the same grid.
3- The main issues is, you need to pass an object from the GRID to the update function, and that object has to match exactly the fields in the grid.
4- I created a table class in my data context with properties exactly the same as the fields in the grid.
5- I changed the update function to have the send parameter with the new created class instead of the original table class from the database.
6- I used the original class to save the data.
7- returned fake transaction result for success.
That stopped this error of happening.
I still believe that Intersoft need to fox that from the engine instead of creating fake classes like that.
Can you post the code edits you made to fix this?
Dave
Hi Guys,
I was not correct on my previous message about the root cause of this error.
Now, I think I got it correct this time and I was able to even make it happen with the ClientBinding_BatchUpdate.aspx Intersoft sample.
So, in the BugTrackerModel.designer.cs, if you define
namespace DataSet
{
.
}
That will make the error happen too.
In ClientBinding_BatchUpdate.aspx we have this function:
function Bug() { this.__type = "Bug"; this.BugId = -1; this.Dupe = null; this.ChangeInLast = null; this.Component = null; this.Severity = null; this.OpSys = null; this.Target = null; this.Summary = null; }
So to make it work again, change it to:
function Bug() { this.__type = "DataSet.Bug"; this.BugId = -1; this.Dupe = null; this.ChangeInLast = null; this.Component = null; this.Severity = null; this.OpSys = null; this.Target = null; this.Summary = null; }
That set!
Damn, three days to find out that!
I guess Intersoft need to change their sample to match this scenario!
Maged Mikaeel
BugId = bugWithOwner.BugId,
Dupe = bugWithOwner.Dupe,
ChangeInLast = bugWithOwner.ChangeInLast,
Component = bugWithOwner.Component,
Severity = bugWithOwner.Severity,
OpSys = bugWithOwner.OpSys,
Target = bugWithOwner.Target,
Summary = bugWithOwner.Summary,
};
OriginalBug.BugId = NewBug.BugId;
OriginalBug.Dupe = NewBug.Dupe;
OriginalBug.ChangeInLast = NewBug.ChangeInLast;
OriginalBug.Component = NewBug.Component;
OriginalBug.Severity = NewBug.Severity;
OriginalBug.OpSys = NewBug.OpSys;
OriginalBug.Target = NewBug.Target;
OriginalBug.Summary = NewBug.Summary;
OwnerId = bugWithOwner.OwnerId,
OwnerName = bugWithOwner.OwnerName,
OriginalOwner.OwnerName = NewOwner.OwnerName;
context.Owners.Attach(NewOwner);
context.SubmitChanges();
AffectedResults = 0,
Exception = null,ExceptionHandled = false, OperationType = DataSourceOperation.BatchUpdate,ReturnValue =
ExceptionHandled = false, OperationType = DataSourceOperation.BatchUpdate,ReturnValue =
OperationType = DataSourceOperation.BatchUpdate,ReturnValue =
ExceptionHandled = false,OperationType = DataSourceOperation.BatchUpdate, ReturnValue =
OperationType = DataSourceOperation.BatchUpdate, ReturnValue =
I already asked you about BatchUpdate in my previous post. I am also interested in how you implemented the Select method. Below is my attempt. I create a query which joins the two tables and places the result in a custom class which I created manually. My solution works but is very inefficient because I have to enumerate the query and place the results into a list. If I don't, the select method throws the following exception:
"IntersoftWebApp1.BugWithOwner' is not a valid metadata type for type filtering operations. Type filtering is only valid on entity types and complex types."
This is my code. Would you share your solution??
BugId = b.BugId,
ChangeInLast = b.ChangeInLast,
Component = b.Component,
Dupe = b.Dupe,
OpSys = b.OpSys,
Severity = b.Severity,
Summary = b.Summary,
Target = b.Target,
OwnerId = j.OwnerId == null ? -1 : j.OwnerId, OwnerName = j.OwnerName == null ? "" : j.OwnerName, };
OwnerName = j.OwnerName == null ? "" : j.OwnerName, };
IList<BugWithOwner> l = new List<BugWithOwner>();
WebGridDataProvider<BugWithOwner> provider = new WebGridDataProvider<BugWithOwner>(l.AsQueryable());
Hi Dave,
I found so limitation on LINQ sql, so I decide to take different root.
For example it doesn't support left join easily...etc
So you can simply run your own SQL statements on different classes/functions and from there you can collect data from different tables on store it on LINQ table on extra fields you can create manually, so next is example of that:
[WebMethod] public object GetMembershipTransactions(DataSourceSelectArguments selectArguments) { MembershipDataContext context = new MembershipDataContext(); context.DeferredLoadingEnabled = false; context.ObjectTrackingEnabled = false; int nMembershipID = 0; Int32.TryParse(selectArguments.FilterExpression, out nMembershipID); var MembershipTransactions = from membershipTransaction in context.MembershipTransactions where membershipTransaction.MembershipID == nMembershipID select new { MembershipTransactionID = membershipTransaction.MembershipTransactionID, TransactionDate = membershipTransaction.TransactionDate, Amount = membershipTransaction.Amount, ChequeNo = GetChequeNo(membershipTransaction.MembershipChequeID), CreditCardNo = GetCreditCardInfo(membershipTransaction.CreditCardID), Processed = membershipTransaction.Processed, ProcessDate = membershipTransaction.ProcessDate, ReferenceNo = membershipTransaction.ReferenceNo, Note = membershipTransaction.Note }; return MembershipTransactions.ToList(); throw new InvalidOperationException("Unsupported operation type!"); }
As you can see, the credit card no and cheque no, I got them from different table and function without the hasle of LINQ sql statements.
Or you can even do something like this (even better:
You can do something like this, which works better too:
[WebMethod] public object GetMembershipNotes(DataSourceSelectArguments selectArguments) { String[] strParameters = selectArguments.FilterExpression.Split(','); int nMembershipID = 0, nEntityTypeID = 0, nNoteType = 0; Int32.TryParse(strParameters[0], out nEntityTypeID); Int32.TryParse(strParameters[1], out nNoteType); Int32.TryParse(strParameters[2], out nMembershipID); ArrayList list = new ArrayList(); foreach(Business.Note note in Business.NoteController.GetNotesForEntityAndNoteType(nEntityTypeID, nMembershipID, nNoteType) ) { Note msNote = new Note(); msNote.NoteID = note.NoteID; msNote.FullName = note.User.LastName + ", " + note.User.FirstName; msNote.CreateDate = note.CreateDate; msNote.Text = note.Text; list.Add(msNote); } return list; throw new InvalidOperationException("Unsupported operation type!"); }
On this example, I completely got the data from outside the LINQ and just stored it in list of LIN table.
For updates, you can do this:
[WebMethod] public TransactionResult UpdateMembershipCheque(MembershipCheque newObject, MembershipCheque originalObject) { Business.MembershipCheque cheque = Business.MembershipChequeController.GetMembershipCheque(originalObject.MembershipChequeID); cheque.BatchNo = newObject.BatchNo; cheque.ChequeNo = newObject.ChequeNo; cheque.DepositDate = newObject.DepositDate; cheque.DueDate = newObject.DueDate; cheque.Save(); MembershipDataContext context = new MembershipDataContext(); return new TransactionResult() { OperationType = DataSourceOperation.Update, ReturnValue = true }; }
So you can build your classes and functions normally outside the LINQ schema, you on that case will need linq to exchange the data that you already collcted it.
I hope that will help you better.
I hope that works good for you too.
or
Choose this if you're already a member of Intersoft Community Forum. You can link your OpenID account to your existing Intersoft Social ID.
Choose this if you don't have an Intersoft account yet. Your authenticated OpenID will be automatically linked to your new Intersoft account.
Enter your Wordpress Blogname