I am using EntityFramework 5 (or 4.3 for .Net Framework 4.0)
In my DbContext object, I already set the correct DbSets, and the objects contain the correct links to each other. This is not new to me, and everything works well.
Now in this case, I have compound keys, which sometimes include the foreign key of the table (or the object in this case). To do this, I use the HasKey<>() function in the HasKey<>() method for DbContext. When these properties have different names, there is no problem, but when these properties have the same name, migration cannot be performed.
Example:
protected override void OnModelCreating(DbModelBuilder modelBuilder) {
As you can see in the presented code, the PatientVisit object has a property called Code, but this property can be repeated as long as it is repeated with another patient. Essence The patient also has a key defined as a "Code".
An anonymous type cannot have two properties, invoking the same name (obviously). A typical solution would be to name anonymous type properties as follows:
protected override void OnModelCreating(DbModelBuilder modelBuilder) {
But at the same time, when I try to add a migration, this error message is called.
The properties expression 'x => new <>f__AnonymousType3`2(PatientCode = x.Patient.Code, VisitCode = x.Code)' is not valid. The expression should represent a property: C
Isaac llopis
source share