We have a MS SQL SERVER table structure like such:
Table Org {
Id Int
Name Varchar(50)
}
Table Request {
Id Int
Name Varchar(50)
OrgId int Not Null
}
Our Models look like this:
public class Org
{
public int Id { get; set;}
public string Name { get; set;}
public List<Request> Requests { get; set;}
}
public class Request
{
public int Id { get; set;}
public string Name { get; set;}
public int OrgId { get; set;}
}
And our configuration is like such:
public class RequestConfiguration : EntityTypeConfiguration<Request>
{
public RequestConfiguration()
{
HasRequired(o => o.Org)
.WithMany(o => o.Requests)
.HasForeignKey(o => o.OrgId);
}
}
Every time I go to make a new Request Instance, and assign an Org to it, it creates a NEW record in the Org table - no matter what. This is on the same dbcontext. I've tried various mappings in the configuration, all result in the same behavior. What am I doing wrong?
Thanks!