I have 2 classes:
public class office
{
[Key]
public Guid ID { get; set; }
//...and some more fields...
}
and
public class room
{
[Key]
public Guid ID { get; set; }
[Foreignkey("office")]
public Guid ID_office { get; set; }
//...and some more fields...
public virtual office office { get; set; }
}
In database context I did the following mapping:
modelBuilder.Entity<room>().HasRequired(n => n.office).WithRequiredPrincipal();
Because I need exactly ONE (required) office for each room. Each office may have rooms (none, one or many) but this relation is not needed in the application. I've tested a lot of variations how to specifiy the relation but always getting errors. What is the correct way to specify this relation?
To make it clearly: I need a required office_id at each room(one-to-one) an no back relation from office to rooms. My problem: with the relations as specified above, Entity Framework always throws an error saying that 'room_id' not found in office model. How to solve this problem?