EF not picking up a foreign key relationship RRS feed

  • Question

  • I have 2 tables in my database. A Company table and a person table. 

    Company Table 

    PK CompanyId varchar(100)


    Person Table

    PK PersonId int
         CompanyId varchar(100)


    I setup a foreign key relationship between Company.CompanyId and Person.CompanyId. For some reason my model does not pick up the relationship. It works fine if I change companyId to an int, but doesnt seem to work if I use varchar. Does EF not support FK based on VarChars?


    Friday, April 9, 2010 5:23 PM


  • Can you post the complete DDL for your schema? I have no problem getting this to work in eitehr VS2008 SP1 or VS2010. From the EDM spec:

    An EntityType must define a Key that consists of one or more of the properties defined for that type. Any set of SimpleType properties can serve as the Key. None of the properties used in the Key can be Null in application code.


    Using a String type as the Key is not a good practice for reasons of both performance and predictability; the meaning of str1 == str2 is highly ambiguous.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Friday, April 9, 2010 7:50 PM