Your foreign key fields are not displayed, so they cannot be interpreted by the proxy code generator (a piece of code called to create your proxy at compile time).
You should put you dbcontext something like
protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Character>() .HasRequired(x=> x.Person) .WithMany(x=> x.Characters) .HasForeignKey(x=> x.PersonId); }
also, I suggest you change your
public virtual List<Character> Characters { get; set; }
on public virtual ICollection<Character> Characters { get; set; } public virtual ICollection<Character> Characters { get; set; } public virtual ICollection<Character> Characters { get; set; } , because I'm not sure that the proxy generator (and EF too) will display this list correctly.
EDIT:
I think that EF Metadataprovider does not supply the correct attribute in the description.
Put a KeyAttribute over Character.CharacterId and Person.PersonID, also add this line on top of Character.Person
[Association("Character_Person", "PersonId", "PersonId", IsForeignKey = true)]
and this character is over Person.Characters
Association("Character_Person", "PersonId", "PersonId")]<br>
EDIT:
After chatting with KitKat, we finally found a problem. During proxy generation, the call to Assembly.GetExportedTypes crashed, requiring EF 4.1. Simple placement
<runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" /> </dependentAssembly> </assemblyBinding>
tricks were performed in the appropriate configuration
Note: this blog post is from mine, which better explains how to deal with EF5 Code first and WCF Ria Services
source share