I'm using entity Framework.
I have an Class named "Child1"
I'm using 2 expression using Ctype and CTypeDynamic:
1)2)Code:Element=CType(Object1,Child1)I pass the element to this function ( entity parameter ):Code:Dim t as type Dim s as string = "MyProg1.Child1,MyProg1,Version=1.0.0, Culture=neutral,PublicKeyToken=null" t=System.Type.GetType(s) Element=CtypeDynamic(Object1,t)
When I use Ctype to get the element , everything is working correctly with the function call.Code:Public Function CopyEntity(Of T As {Class, New})(ctx As MyEntities, entity As T, Optional copyKeys As Boolean = False) As T Dim clone As New T() Dim en = ctx.Entry(clone) en.State = System.Data.Entity.EntityState.Added ctx.Entry(clone).CurrentValues.SetValues(entity) en.State = System.Data.Entity.EntityState.Detached Return clone End Function
When I use the second case ( with CTypeDynamic ) , when I call the function I get an error on this line :
What's the problem in second case , because I want to make it work ( of course I don't want to change the logic of my code in second case , so the type is in a string variable first ).Code:Dim en = ctx.Entry(clone) An unhandled exception of type 'System.InvalidOperationException' occurred in EntityFramework.dll Additional information: The entity type Object is not part of the model for the current context.
Thank you !


Reply With Quote
