Question: I have a WCF project referring another DAL project with entity framework 5 EDMX.

I can't retrieve the metadata of my service : <http://localhost:12034/DataService.svc/>$metadata

Its returning following error :

> 
> An IEdmModel instance was found that failed validation. The following errors were reported: 
>  TypeMismatchRelationshipConstraint : The types of all properties in the dependent role of a referential constraint must be the same as the corresponding property types in the principal role. The type of property 'TenantID' on entity 'PScopeModel.Resource' does not match the type of property 'ResourceTypeID' on entity 'ResourceType' in the referential constraint 'Fred'.
> 
> 
> TypeMismatchRelationshipConstraint : The types of all properties in the dependent role of a referential constraint must be the same as the corresponding property types in the principal role. The type of property 'ResourceType' on entity 'PScopeModel.Resource' does not match the type of property 'TenantID' on entity 'ResourceType' in the referential constraint 'Fred'.
> 
> 
> TypeMismatchRelationshipConstraint : The types of all properties in the dependent role of a referential constraint must be the same as the corresponding property types in the principal role. The type of property 'TenantID' on entity 'PScopeModel.Resource' does not match the ty...
> 
> 
> 

I basically have following relationship
![Relationship](https://i.stack.imgur.com/EQjIL.png)

ResourceType table has PK on TenantID + ResourceTypeID
Resource table has PK on TenantID + ResourceID and FK on ResourceType.

This seems to be affecting all FKs on my framework, since if I remove the current impacted relation, it will occur on another relationship.

Individual entities are displayed correctly : <http://localhost:12034/DataService.svc/ResourceTypes>

Answer: 
That seems an issue of WCF Data Services with the composite key's order. A related thread: [Getting Metadata TypeMismatchRelationshipConstraint error for WCF Data Services project](https://social.msdn.microsoft.com/Forums/en-US/242da242-f2a9-498d-8f68-a29ef19ab222/getting-metadata-typemismatchrelationshipconstraint-error-for-wcf-data-services-project?forum=adodotnetdataservices).

Key sorted in data service type: [ResourceType](https://msdn.microsoft.com/en-us/library/system.data.services.providers.resourcetype(v=vs.113).aspx), and then propagated to entity type, but not sorted in navigationProperty's dependent properties.

A solution is to disable the model validation for the case, e.g.:

```
public static void InitializeService(DataServiceConfiguration config)
{
    ...
    config.DisableValidationOnMetadataWrite = true;

```

Or, give it a try about [OData Web API](http://www.asp.net/web-api/overview/odata-support-in-aspnet-web-api)'s [5.4 beta](http://blogs.msdn.com/b/odatateam/archive/2015/01/23/announcement-odata-web-api-5-4-beta.aspx) which has [Referential Constraint support](http://odata.github.io/WebApi/referential-constraint/), or [RESTier](https://github.com/OData/RESTier/wiki).
In your db, check the datatype of ResourceType on the Resource table, and verify it's the same datatype of the ResourceTypeID on the ResourceType table. Do the same for the TenantID field.

As long as those are the same, update your EDMX from the table, then, right click in your EDMX file and click, "Add Code Generation Item" and replace your current .tt files by saving the new ones you are generating as the same names as your current files and electing to overwrite existing. This will basically refresh your EDMX references to the tables and their relations.

This may fix the problem. EDMX is finicky and if you don't follow the steps properly and update correctly, you will sometimes run into these issues.