CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Dec 2011
    Location
    .Net 4.0
    Posts
    39

    Displaying Data from SQL Express db

    NM, I fixed it. Seems I had to just reload the revised database by adding new data source. If anyone is inclined, I'd like to know how to avoid this from happening again. Was it because I failed to include a db refresh on stored procedures in C# wizard?


    I used this simple loop to show me my table data:

    using (var dbContext = new TestEntities())
    {
    var names = from Name in dbContext.Clients
    select Name;
    foreach (var name in names)
    {
    MessageBox.Show(name.Name + " " + name.Address);
    }

    }

    Then, I updated the table in SQL Studio to add an Id column, and I added an Invoices table to the db. I also set primary keys, indexes and a relation, all in Server Studio.

    I refreshed my database in VS C# with the wizard. The text editor recognizes my new tables and columns, but the above code no longer works.

    Here's what I think might be relevant in the error message detail:

    Message=
    Model1.msl(6,10) : error 3002: Problem in mapping fragments starting at line 6:Potential runtime violation of table Clients's keys (Clients.Id): Columns (Clients.Id) are mapped to EntitySet Clients's properties (Clients.Id) on the conceptual side but they do not form the EntitySet's key properties (Clients.Id, Clients.Name).


    Here's the full error message detail:

    System.Data.EntityCommandCompilationException was unhandled
    Message=An error occurred while preparing the command definition. See the inner exception for details.
    Source=System.Data.Entity
    StackTrace:
    at System.Data.EntityClient.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree)
    at System.Data.EntityClient.EntityProviderServices.CreateCommandDefinition(DbProviderFactory storeProviderFactory, DbCommandTree commandTree)
    at System.Data.EntityClient.EntityProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
    at System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
    at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Prepare(ObjectContext context, DbQueryCommandTree tree, Type elementType, MergeOption mergeOption, Span span, ReadOnlyCollection`1 compiledQueryParameters)
    at System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
    at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
    at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
    at WindowsFormsApplication1.Form1..ctor() in C:\Users\Jeff\documents\visual studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs:line 31
    at WindowsFormsApplication1.Program.Main() in C:\Users\Jeff\documents\visual studio 2010\Projects\WindowsFormsApplication2\WindowsFormsApplication2\Program.cs:line 18
    at System.AppDomain._nExecuteAssembly(RuntimeAssembly 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, Boolean ignoreSyncCtx)
    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
    at System.Threading.ThreadHelper.ThreadStart()
    InnerException: System.Data.MappingException
    Message=
    Model1.msl(6,10) : error 3002: Problem in mapping fragments starting at line 6:Potential runtime violation of table Clients's keys (Clients.Id): Columns (Clients.Id) are mapped to EntitySet Clients's properties (Clients.Id) on the conceptual side but they do not form the EntitySet's key properties (Clients.Id, Clients.Name).

    Source=System.Data.Entity
    StackTrace:
    at System.Data.Mapping.StorageMappingItemCollection.ViewDictionary.SerializedGenerateViews(EntityContainer container, Dictionary`2 resultDictionary)
    at System.Data.Mapping.StorageMappingItemCollection.ViewDictionary.SerializedGetGeneratedViews(EntityContainer container)
    at System.Data.Common.Utils.Memoizer`2.<>c__DisplayClass2.<Evaluate>b__0()
    at System.Data.Common.Utils.Memoizer`2.Result.GetValue()
    at System.Data.Common.Utils.Memoizer`2.Evaluate(TArg arg)
    at System.Data.Mapping.StorageMappingItemCollection.ViewDictionary.GetGeneratedView(EntitySetBase extent, MetadataWorkspace workspace, StorageMappingItemCollection storageMappingItemCollection)
    at System.Data.Metadata.Edm.MetadataWorkspace.GetGeneratedView(EntitySetBase extent)
    at System.Data.Query.PlanCompiler.PreProcessor.ExpandView(Node node, ScanTableOp scanTableOp, IsOfOp& typeFilter)
    at System.Data.Query.PlanCompiler.PreProcessor.ProcessScanTable(Node scanTableNode, ScanTableOp scanTableOp, IsOfOp& typeFilter)
    at System.Data.Query.PlanCompiler.PreProcessor.Visit(ScanTableOp op, Node n)
    at System.Data.Query.InternalTrees.ScanTableOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
    at System.Data.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
    at System.Data.Query.PlanCompiler.SubqueryTrackingVisitor.VisitChildren(Node n)
    at System.Data.Query.PlanCompiler.SubqueryTrackingVisitor.VisitRelOpDefault(RelOp op, Node n)
    at System.Data.Query.PlanCompiler.PreProcessor.Visit(ProjectOp op, Node n)
    at System.Data.Query.InternalTrees.ProjectOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
    at System.Data.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
    at System.Data.Query.PlanCompiler.SubqueryTrackingVisitor.VisitChildren(Node n)
    at System.Data.Query.PlanCompiler.SubqueryTrackingVisitor.VisitRelOpDefault(RelOp op, Node n)
    at System.Data.Query.PlanCompiler.PreProcessor.Visit(ProjectOp op, Node n)
    at System.Data.Query.InternalTrees.ProjectOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
    at System.Data.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
    at System.Data.Query.PlanCompiler.SubqueryTrackingVisitor.VisitChildren(Node n)
    at System.Data.Query.InternalTrees.BasicOpVisitorOfNode.VisitDefault(Node n)
    at System.Data.Query.InternalTrees.BasicOpVisitorOfNode.VisitPhysicalOpDefault(PhysicalOp op, Node n)
    at System.Data.Query.InternalTrees.BasicOpVisitorOfT`1.Visit(PhysicalProjectOp op, Node n)
    at System.Data.Query.InternalTrees.PhysicalProjectOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
    at System.Data.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
    at System.Data.Query.PlanCompiler.PreProcessor.Process()
    at System.Data.Query.PlanCompiler.PreProcessor.Process(PlanCompiler planCompilerState, StructuredTypeInfo& typeInfo)
    at System.Data.Query.PlanCompiler.PlanCompiler.Compile(List`1& providerCommands, ColumnMap& resultColumnMap, Int32& columnCount, Set`1& entitySets)
    at System.Data.EntityClient.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree)
    InnerException:
    Last edited by JeffInTexas; December 8th, 2011 at 11:04 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured