You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to add Triggers in both a parent (CreatedEntity) and child (ModifiedCreatedEntity) class, but I keep hitting an InvalidCastException (details below) on context.SaveChanges()
Moving both the triggers to either the parent or child class resolves the problem, but isn't as nice design-wise, since I would like some entity classes to inherit from the parent (with its properties and associated triggers) and other entity classes to inherit from the child (with both the parent and child properties and triggers). Any help or advice would be greatly appreciated.
System.InvalidCastException was unhandled
HResult=-2147467262
Message=Unable to cast object of type 'EntityFramework.Triggers.Triggers`1[CreatedEntity]' to type 'EntityFramework.Triggers.Triggers`1[ModifiedCreatedEntity]'.
Source=EntityFramework.Triggers
StackTrace:
at EntityFramework.Triggers.Extensions.Triggers[TTriggerable](TTriggerable triggerable)in c:\Development\EntityFramework.Triggers\EntityFramework.Triggers\Extensions.cs:line 27
at ModifiedCreatedEntity..ctor()in c:\Users\user\Documents\Visual Studio 2013\Projects\TriggerTestApp\TriggerTestApp\Program.cs:line 20
at Program.Main(String[]args) in c:\Users\user\Documents\Visual Studio 2013\Projects\TriggerTestApp\TriggerTestApp\Program.cs:line 45
at System.AppDomain._nExecuteAssembly(RuntimeAssemblyassembly, 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.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
The text was updated successfully, but these errors were encountered:
I have some code that does this same thing, and it seems to be broken with this version which means there was a regression. I designed it to handle this situation, and I've obviously overlooked something. I'm looking at the code now.
@ConradPoohs I have pushed a fix to the master branch, as well as the appropriate test to make sure it doesn't break base class triggers again. Please do a pull on your clone or update your NuGet package. Enjoy!
Trying to add Triggers in both a parent (
CreatedEntity
) and child (ModifiedCreatedEntity
) class, but I keep hitting anInvalidCastException
(details below) oncontext.SaveChanges()
Moving both the triggers to either the parent or child class resolves the problem, but isn't as nice design-wise, since I would like some entity classes to inherit from the parent (with its properties and associated triggers) and other entity classes to inherit from the child (with both the parent and child properties and triggers). Any help or advice would be greatly appreciated.
Sample Code:
Exception:
The text was updated successfully, but these errors were encountered: