Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I have an EDMX model with a generated context.
Now i generated a Self Tracking Entities library is separate project and referenced this from the EDMX model.
Also set the correct namespace in the context to the same namespace as the entities.

Now working with this all works except when i try to create a WCF data service with this context.

So just create new ObjectContext and working with it directly works fine.

But having referenced the context + model lib and the entities lib i get the following error when loading the service

The server encountered an error processing the request. The exception message is 'Value cannot be null. Parameter name: key'. See server logs for more details. The exception stack trace is:

Now i found that this could happen when using data service with external entity lib and fix was overriding the createcontext

with code

XML
System.Data.Metadata.Edm.ItemCollection itemCollection;
        if (!context.MetadataWorkspace.TryGetItemCollection
              (System.Data.Metadata.Edm.DataSpace.CSSpace, out itemCollection))
        {
            var tracestring = context.CreateQuery<ClientDataStoreContainer>("ClientDataStoreContainer.DataSet").ToTraceString();
        }
        return context;




Now the error is gone but i get the next one and that is:
Object mapping could not be found for Type with identity 'ClientDataStoreEntities.Data'.
This error occurs on the .toTraceString in the createcontext

the ssdl file has the defined type
XML
<EntitySetMapping Name="DataSet">
    <EntityTypeMapping TypeName="IsTypeOf(ClientDataStoreEntities.Data)">


So it has to load the ClientDataStoreEntities.Data type which is the namespace and type of the STE library that i have generated from the model.

XML
EDIT: with var tracestring = context.CreateQuery<Data>("ClientDataStoreContainer.DataSet").ToTraceString();
It does seem to load all types , however now the service does not have any methods that i can call.
there should be 2 DataSet and PublishedDataSet but:
<service xml:base="http://localhost:1377/WcfDataService1.svc/"><workspace>
<atom:title>Default</atom:title>
</workspace>
</service> is what i get.
Posted
Updated 2-Dec-10 5:59am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900