Resolving Entity Framework Entity

May 27, 2010 at 1:30 AM

Using the Entity Framework i have an Entity Container  named CC

i am trying to do this unsuccessfully

CC context = new CC();             

Container.RegisterInstance<CC>("context", context,(new ContainerControlledLifetimeManager()));

 

Then in one of my Classes i try this:

context = container.Resolve("context");

But when i try to use context to something like:

context.Pacientes.ToList();

I get 

 

Microsoft.Practices.Unity.ResolutionFailedException was unhandled by user code  Message=Resolution of the dependency failed, type = "Pacientes.View", name = "". Exception message is: The current build operation (build key Build Key[Pacientes.View, null]) failed: An error occurred while executing the command definition. See the inner exception for details. (Strategy type BuildPlanStrategy, index 3)  Source=Microsoft.Practices.Unity  TypeRequested=View  StackTrace:       at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name)       at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, String name)       at Microsoft.Practices.Unity.UnityContainer.Resolve(Type t, String name)       at Microsoft.Practices.Unity.UnityContainerBase.Resolve(Type t)       at Microsoft.Practices.Unity.UnityContainerBase.Resolve[T]()       at Pacientes.Pacientes.Initialize() in C:\Visual Studio Projects\Gaia\Pacientes\Pacientes.cs:line 42       at Microsoft.Practices.Composite.Modularity.ModuleInitializer.Initialize(ModuleInfo moduleInfo)  InnerException: Microsoft.Practices.ObjectBuilder2.BuildFailedException       Message=The current build operation (build key Build Key[Pacientes.View, null]) failed: An error occurred while executing the command definition. See the inner exception for details. (Strategy type BuildPlanStrategy, index 3)       Source=Microsoft.Practices.ObjectBuilder2       BuildKey=Build Key[Pacientes.View, null]       ExecutingStrategyIndex=3       ExecutingStrategyTypeName=BuildPlanStrategy       StackTrace:            at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)            at Microsoft.Practices.ObjectBuilder2.Builder.BuildUp(IReadWriteLocator locator, ILifetimeContainer lifetime, IPolicyList policies, IStrategyChain strategies, Object buildKey, Object existing)            at Microsoft.Practices.Unity.UnityContainer.DoBuildUp(Type t, Object existing, String name)       InnerException: System.Data.EntityCommandExecutionException            Message=An error occurred while executing the command definition. See the inner exception for details.            Source=System.Data.Entity            StackTrace:                 at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)                 at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)                 at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)                 at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()                 at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)                 at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)                 at Pacientes.View..ctor(IUnityContainer container, IEventAggregator eventAggregator) in C:\Visual Studio Projects\Gaia\Pacientes\View.xaml.cs:line 55                 at BuildUp_Pacientes.View(IBuilderContext )                 at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)                 at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)                 at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)            InnerException: System.Data.SqlServerCe.SqlCeException                 Message=The column name is not valid. [ Node name (if any) = Extent1,Column name = MedicoCRM ]                 Source=SQL Server Compact ADO.NET Data Provider                 HResult=-2147217900                 NativeError=25503                 StackTrace:                      at System.Data.SqlServerCe.SqlCeCommand.CompileQueryPlan()                      at System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options)                      at System.Data.SqlServerCe.SqlCeCommand.ExecuteReader(CommandBehavior behavior)                      at System.Data.SqlServerCe.SqlCeCommand.ExecuteDbDataReader(CommandBehavior behavior)                      at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)                      at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)                 InnerException: 

 

ps: I am using Prism and this exception happens when i create the view 

           View view = unitContainer.Resolve<View>();

but if i don't use the context as i showed in the beginning ... context.Pacientes.ToList();   i don't  get that monster error     what i am doing wrong?

May 27, 2010 at 4:14 AM
The actual error is buried, but it's in there, specifically:
Message=The column name is not valid. [ Node name (if any) = Extent1,Column name = MedicoCRM ] Source=SQL Server Compact ADO.NET Data Provider HResult=-2147217900 NativeError=25503

Looks like you've got an issue with your context definition.