-
-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update error when a table has two foreign keys pointing to the same table #168
Comments
Hello @fdahlberg , Thank you for reporting, I will try to check this issue tomorrow or during next week. Best Regards, Jonathan Help us to support this library: Donate |
This is not a GraphDiff problem but most probably something wrong with your entity configuration. How does your fluent API look like? |
Hi cryo75, |
How are you mapping the properties to the columns? And where is the Person_id column? In Person on in WorkItem? |
The Person_id column is created automatically by Entity Framework, because I have a naviagation property on Person (WorkItems). |
So you have Person_Id and Creator_Id in the workitems table? Am I understanding correctly? And why do you want 2 foreign keys pointing to the same table? I usually do my own mapping. However, what I can see is this:
Shouldn't that be:
|
That's correct! In my example (the real situation is much more complicated) I want to say that a person has a number of workitems, but the workitem is also created by a person (differenct from the owner). Therefore, as far as I can understand I need 2 foreign keys pointing to the same table (Person). Would you have solved it differently? The Graphdiff mapping that you suggest is what I started with. I added the associated entity part as an attempt to solve it, but it didn't change anything. |
This is EF-related. I guess you will need another Person property (Owner) in your WorkItem because Creator will always be the same as Person. |
Tried adding a property on WorkItem called Owner and changing the fluen API to: Same result unfortunately. Not sure it's EF related since it works fine if I add a Person object in the normal EF way. This is the code that works fine, meaning that only Owner_id is populated:
When I run the following graphdiff it doesn't work:
After having run these two methods the database looks like this: So what I can't understand is why Creator_id is populated when I use graphdiff. |
Can you set up a sample project, zip it and attach it here so I can have a look at it. |
This is the project I'm using to test this issue: |
I know that it works fine when you're not using GraphDiff. My problem is when you use GraphDiff... |
I noticed. I'm getting the same Id's when using GraphDiff. Trying to see what the problem is. |
Excellent! Then we're on the same page! |
Hello @fdahlberg , Sorry for the delay, we forget to add this issue to our task list. My developer tried your scenario, one problem he noted is that you call protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Person>()
.HasMany(p => p.WorkItems)
.WithRequired()
.WillCascadeOnDelete();
base.OnModelCreating(modelBuilder);
} Let me know if that once when moving Best Regards, Jonathan Help us to support this library: Donate |
Hello @fdahlberg , I will close this issue since it seems to be solved. Feel free to reopen it if there is something else. Best Regards, Jonathan Help us to support this library: Donate |
Hi Jonathan, I tried the suggested solution but couldn't see any difference. Acccording to the documentation for OnModelCreating the base implementation does nothing. So how could it matter whether I call it first or last or not at all in the method? Kind Regards |
Hello @fdahlberg , I don't understand either, I just know that if we put this line before it doesn't work, but when we put this line after, it works on our side. Could you at least try it? Best Regards, Jonathan Help us to support this library: Donate |
Hi Jonathan, I have tried it. It didn't work for me. Fred |
We will investigate again, don't worry ;) I'm also curious why it started to work on our side magically! Best Regards, Jonathan Help us to support this library: Donate |
Hi @JonathanMagnan, was this ever looked at again? I have come across this same problem and am wondering if there will be a fix coming? |
Hello @hprutsman , To be honest, yes it will be looked again but not in a very short term. We are currently trying to close all issues related to One problem with this request if I remember well is how FK are handled. They are a huge flaw in the logic with this scenario that requires some heavy work on our side. The logic simply doesn't work. We will need soon to implement Best Regards, Jonathan |
@JonathanMagnan, hi! Thank you for this awesome library. I faced with the same problem in EF6, any news when it'll be fixed? |
@JonathanMagnan, is any progress on this? |
Hi,
I have the following model:
My fluent API looks like this:
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:
The text was updated successfully, but these errors were encountered: