I have two classes as follows.
class Donkey
{
public Guid Id { get; set; }
}
class Monkey
{
public Guid Id { get; set; }
public Donkey Donkey { get; set; }
}
Now I want to configure the schema so that the relation is set in the database. Using Fluent API, I'll go something like this.
protected override void OnModelCreating(DbModelBuilder model)
{
base.OnModelCreating(model);
model.HasDefaultSchema("dbo");
...
model.Entity<Monkey>
.HasRequired(_ => _.Donkey)
.WithMany(_ => _.Monkeys)
.Map(_ => _.MapKey("DonkeyId"));
}
The problem is that now I have to declare a list of monkeys in the donkey. And I don't want to do that. I still want the monkey to point to a donkey using foreign key, so only required status won't do, because I need to specify my custom column name to store the FK pointing to the PK in the table of donkeys.
model.Entity<Monkey>.HasRequired(_ => _.Donkey);
So, the above lacks the mapping (and it doesn't compile when I just add it). Is there a way to work around it without actually changing the definition of Donkey class?