CanRemoveItem

CanRemoveItem

Old forum URL: forums.lhotka.net/forums/t/7973.aspx


Adam posted on Wednesday, November 11, 2009

Hi guys

I have the following which I was expecting to diable the delete button when an item cannot be deletede but it doens't appear to work as the delete button is enabled and when an accept is performed it gives the error message below. Any help appreciated.

<Button x:Name="DeleteButton" Content="Delete" Margin="3"
                    csla:InvokeMethod.MethodName="RemoveItem"
                    csla:InvokeMethod.Resource="{StaticResource metaHardwareSupplierListData}"
                    csla:InvokeMethod.TriggerEvent="Click"
                    csla:InvokeMethod.MethodParameter="{Binding}"
                    IsEnabled="{Binding Mode=OneWay, Path=CanRemoveItem}"
                    Style="{StaticResource Button}"/>

Error Message:
Csla.DataPortalException occurred
  Message="DataPortal.Update failed (System.Data.SqlClient.SqlException: The DELETE statement conflicted with the REFERENCE constraint \"FK_EquipmentHistory_meta_HardwareSupplier\". The conflict occurred in database \"MobileSalesAssistant\", table \"dbo.EquipmentHistory\", column 'HardwareSupplierId'.\r\nThe statement has been terminated.\r\n   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)\r\n   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)\r\n   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)\r\n   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)\r\n   at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)\r\n   at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)\r\n   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)\r\n   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()\r\n   at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)\r\n   at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)\r\n   at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)\r\n   at System.Data.Linq.ChangeDirector.StandardChangeDirector.DynamicDelete(TrackedObject item)\r\n   at System.Data.Linq.ChangeDirector.StandardChangeDirector.Delete(TrackedObject item)\r\n   at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)\r\n   at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)\r\n   at System.Data.Linq.DataContext.SubmitChanges()\r\n   at MobileSalesAssistant.Business.BusinessClasses.meta_HardwareSupplierList.DataPortal_Update() in C:\\FSSLtd\\Perforce\\Products\\MobileSalesAssistant\\MobileSalesAssistantSilverlight\\MobileSalesAssistant.Business.Server\\BusinessClasses\\meta_HardwareSupplierList.cs:line 105\r\n   at dm(Object , Object[] )\r\n   at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in C:\\FSSLtd\\Perforce\\OpenSourceLibs\\cslalightcs-3.7.0-090721\\cslacs\\Csla\\Reflection\\MethodCaller.cs:line 332)"
  Source="Csla"
  StackTrace:
       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
       at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
       at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
       at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
       at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
       at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
       at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
       at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
       at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
       at System.Data.Linq.ChangeDirector.StandardChangeDirector.DynamicDelete(TrackedObject item)
       at System.Data.Linq.ChangeDirector.StandardChangeDirector.Delete(TrackedObject item)
       at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
       at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
       at System.Data.Linq.DataContext.SubmitChanges()
       at MobileSalesAssistant.Business.BusinessClasses.meta_HardwareSupplierList.DataPortal_Update() in C:\FSSLtd\Perforce\Products\MobileSalesAssistant\MobileSalesAssistantSilverlight\MobileSalesAssistant.Business.Server\BusinessClasses\meta_HardwareSupplierList.cs:line 105
       at dm(Object , Object[] )
       at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in C:\FSSLtd\Perforce\OpenSourceLibs\cslalightcs-3.7.0-090721\cslacs\Csla\Reflection\MethodCaller.cs:line 332
       at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in C:\FSSLtd\Perforce\OpenSourceLibs\cslalightcs-3.7.0-090721\cslacs\Csla\Reflection\MethodCaller.cs:line 336
       at Csla.Reflection.MethodCaller.CallMethod(Object obj, String method, Object[] parameters) in C:\FSSLtd\Perforce\OpenSourceLibs\cslalightcs-3.7.0-090721\cslacs\Csla\Reflection\MethodCaller.cs:line 260
       at Csla.Reflection.LateBoundObject.CallMethod(String method) in C:\FSSLtd\Perforce\OpenSourceLibs\cslalightcs-3.7.0-090721\cslacs\Csla\Reflection\LateBoundObject.cs:line 70
       at Csla.Server.SimpleDataPortal.Update(Object obj, DataPortalContext context) in C:\FSSLtd\Perforce\OpenSourceLibs\cslalightcs-3.7.0-090721\cslacs\Csla\Server\SimpleDataPortal.cs:line 230
       at Csla.DataPortal.Update(Object obj) in C:\FSSLtd\Perforce\OpenSourceLibs\cslalightcs-3.7.0-090721\cslacs\Csla\DataPortal.cs:line 480
  InnerException: Csla.Reflection.CallMethodException
       Message="DataPortal_Update method call failed"
       Source="Csla"
       StackTrace:
            at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
            at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
            at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
            at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
            at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
            at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
            at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
            at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
            at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
            at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
            at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
            at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
            at System.Data.Linq.ChangeDirector.StandardChangeDirector.DynamicDelete(TrackedObject item)
            at System.Data.Linq.ChangeDirector.StandardChangeDirector.Delete(TrackedObject item)
            at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
            at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
            at System.Data.Linq.DataContext.SubmitChanges()
            at MobileSalesAssistant.Business.BusinessClasses.meta_HardwareSupplierList.DataPortal_Update() in C:\FSSLtd\Perforce\Products\MobileSalesAssistant\MobileSalesAssistantSilverlight\MobileSalesAssistant.Business.Server\BusinessClasses\meta_HardwareSupplierList.cs:line 105
            at dm(Object , Object[] )
            at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in C:\FSSLtd\Perforce\OpenSourceLibs\cslalightcs-3.7.0-090721\cslacs\Csla\Reflection\MethodCaller.cs:line 332
            at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in C:\FSSLtd\Perforce\OpenSourceLibs\cslalightcs-3.7.0-090721\cslacs\Csla\Reflection\MethodCaller.cs:line 336
            at Csla.Reflection.MethodCaller.CallMethod(Object obj, String method, Object[] parameters) in C:\FSSLtd\Perforce\OpenSourceLibs\cslalightcs-3.7.0-090721\cslacs\Csla\Reflection\MethodCaller.cs:line 260
            at Csla.Reflection.LateBoundObject.CallMethod(String method) in C:\FSSLtd\Perforce\OpenSourceLibs\cslalightcs-3.7.0-090721\cslacs\Csla\Reflection\LateBoundObject.cs:line 70
            at Csla.Server.SimpleDataPortal.Update(Object obj, DataPortalContext context) in C:\FSSLtd\Perforce\OpenSourceLibs\cslalightcs-3.7.0-090721\cslacs\Csla\Server\SimpleDataPortal.cs:line 230
       InnerException: System.Data.SqlClient.SqlException
            Message="The DELETE statement conflicted with the REFERENCE constraint \"FK_EquipmentHistory_meta_HardwareSupplier\". The conflict occurred in database \"MobileSalesAssistant\", table \"dbo.EquipmentHistory\", column 'HardwareSupplierId'.\r\nThe statement has been terminated."
            Source=".Net SqlClient Data Provider"
            ErrorCode=-2146232060
            Class=16
            LineNumber=1
            Number=547
            Procedure=""
            Server=".\\SQLEXPRESS"
            State=0
            StackTrace:
                 at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
                 at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
                 at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
                 at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
                 at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
                 at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
                 at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
                 at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
                 at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
                 at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
                 at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
                 at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
                 at System.Data.Linq.ChangeDirector.StandardChangeDirector.DynamicDelete(TrackedObject item)
                 at System.Data.Linq.ChangeDirector.StandardChangeDirector.Delete(TrackedObject item)
                 at System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
                 at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
                 at System.Data.Linq.DataContext.SubmitChanges()
                 at MobileSalesAssistant.Business.BusinessClasses.meta_HardwareSupplierList.DataPortal_Update() in C:\FSSLtd\Perforce\Products\MobileSalesAssistant\MobileSalesAssistantSilverlight\MobileSalesAssistant.Business.Server\BusinessClasses\meta_HardwareSupplierList.cs:line 105
                 at dm(Object , Object[] )
                 at Csla.Reflection.MethodCaller.CallMethod(Object obj, DynamicMethodHandle methodHandle, Object[] parameters) in C:\FSSLtd\Perforce\OpenSourceLibs\cslalightcs-3.7.0-090721\cslacs\Csla\Reflection\MethodCaller.cs:line 332
            InnerException:

Fintanv replied on Wednesday, November 11, 2009

Well the error is being kicked back from your database where there are child 'supplier equipment' records that are not being deleted prior to attempting to delete the parent 'hardware supplier' record.  Hence you are violating a foreign key constraint.  As to why the delete button is not being disabled, we would have to see the code that controls the value of "CanRemoveItem".

Cheers,

Fintan

Adam replied on Wednesday, November 11, 2009

Hi Fintan

Thanks for the information. The CanRemoveItem part is what I am intrested in and is part of the framework which is why I am wondering why its not working. I am running CSLA 3.7.0 for Silverlight if that helps.

Regards

Adam

RockfordLhotka replied on Wednesday, November 11, 2009

If you are going to manually control the UI control's state you need to tell InvokeMethod to use manual mode - that's another property you need to set on InvokeMethod.

My guess is that InvokeMethod is fighting your manual binding.

Adam replied on Tuesday, November 24, 2009

Ah I see well after many attepts I have found csla:InvokeMethod.ManualEnableControl = "True" but this won't allow me to hide/disable the delete button so I have inplemented CanRemoteItem seperatly and attached it to the Visibility property as that appaers to work! Anyway thanks for the info :)

Copyright (c) Marimer LLC