Silent failure when association does not involve primary keys RRS feed

  • Question


    Hey folks.


    I have two tables.


    The parent has a identity, and a varchar(30) column entitled "Code".


    The child entity has a relationship with the parent through the "Code" column.



    Through triggers and stored procedures, the "code" column gets converted into a combination of a static prefix, and the identity value. The "code" column is indexed(unique) and is not nullable.


    When I drag the tables into the LINQ Designer, the Association is shown graphically.


    When I compile and run my LINQ application, the parent entity can fetch child entities without throwing an exception.


    However, I receive an "Invalid Cast" LINQ error when setting the "Code" column in the child table.


    If I make "Code" nullable, or remove the relationship/association. I do not get this error.





    Friday, March 28, 2008 4:33 PM


  • As there has been no new activity on this thread I am going to mark it as closed. If you wish to continue the discussion feel free to reopen it Smile




    Friday, June 13, 2008 5:17 PM

All replies

  • Can you post the full exception stack trace you are seeing when you get the Invalid Cast error please.






    Monday, June 2, 2008 4:27 PM
  • As there has been no new activity on this thread I am going to mark it as closed. If you wish to continue the discussion feel free to reopen it Smile




    Friday, June 13, 2008 5:17 PM
  • Hi,


    I am also facing the same scenario as you. Did u find solution for this?


    I am getting the InvalidCastException when i try to change and update the child records in Grid.


    Exception Details: InvalidCast Exception


    Stack Trace:


       at LINQToolkit.Form1.btnSave_Click(Object sender, EventArgs e) in D:\Syed\LINQToolkit\LINQToolkit\Form1.vb:line 33
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at Janus.Windows.EditControls.UIButton.OnClick(EventArgs e)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at LINQToolkit.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()


    Tuesday, July 22, 2008 9:09 AM