I have two entities: Job and Orderable on our code-first database:
The (extremely simple) models of these two are:
class Job
{
public Guid Id {get; set;}
public string JobName {get; set;}
public List Items {get; set;}
}
class Orderable
{
public Guid Id {get; set;}
public string MaterialNumber {get; set;}
}
I wanted to be able to reference the Job from the orderable, so I added a property like so:
public Job OwningObject {get; set;}
But when I did the migration, it created a second foreign key for this object. Now, it seems that if I am getting the Orderables from the Job, it uses key1, but if I am getting the Job from the Orderable, it uses key2.
Within our OnmodelCreating method in our context we have added the following before the key was created, which I thought was required to make it work, but I am not sure if this is potentially causing the issue.
modelBuilder.Entity().HasMany(x => x.Items).WithOne();
We were able to force the key to reference the proper field with a data annotation of:
[ForeignKey("OwningObjectId1")]
But this feels hacky and I don't like it as a permanent solution.
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)