开发者

WCF DataService EF entities not found

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

Collapse

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 Collapse

<EntitySetMapping Name="DataSet">
    <Entit开发者_JAVA技巧yTypeMapping 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.

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.


I ran into the same issue (the first one you mention). I have worked around using the suggestion by Julie Lerman in this thread. The other suggestion didn't work for me although I will experiment with them more since Julie's solution may have performance implications since it's executed (and has some cost) for every query.

MSDN Fail to work with POCO ModelContainer which entities are located in other assembly

Edit: Sorry, just realized you utilized the other solution mentioned in this thread.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜