Skip to content

Update error when a table has two foreign keys pointing to the same table #168

Description

@fdahlberg

Hi,

I have the following model:

public class Person
{
public Person()
{
Id = Guid.NewGuid();
WorkItems = new List<WorkItem>();
}
public Guid Id { get; set; }
public string Name { get; set; }
public ICollection<WorkItem> WorkItems { get; set; }
}
public class WorkItem
{
public WorkItem()
{
Id = Guid.NewGuid();
}
public Guid Id { get; set; }
public string Description { get; set; }
public Person Creator { get; set; }
}

My fluent API looks like this:

protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Person>()
.HasMany(p => p.WorkItems)
.WithRequired()
.WillCascadeOnDelete();
}

When I use Graphdiff to update this small graph, I find that the Creator_Id Column in the WorkItem table is constantly set to the same as Person_id column.
I can't understand why this is happening. Is this a bug?

My graphdiff code to update the graph looks like this:

 public static void UpdatePerson(Person person)
{
using (var context = new GraphDiffTestDbContext())
{
context.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);
context.UpdateGraph(person, map => map
.OwnedCollection(p => p.WorkItems, with => with.AssociatedEntity(p => p.Creator))
);
context.SaveChanges();
}
}

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions