Unable to determine the relationship represented by navigation property occurring issue after migration of asp.net core 1.1 to 2.0
public class Contact { public int ContactId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Email { get; set; }
[ForeignKey("CreatedById")] public User CreatedBy { get; set; }
[ForeignKey("UpdatedById")] public User UpdatedBy { get; set; } }
public class User
{
public int UserId { get; set; }
public string UserName { get; set; }
[InverseProperty("CreatedBy")]
public List
//Error on Run Migration
public class Contact
{
public int ContactId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
[ForeignKey("CreatedById")]
public User CreatedBy { get; set; }
[ForeignKey("UpdatedById")]
public User UpdatedBy { get; set; }
}
public class User
{
public int UserId { get; set; }
public string UserName { get; set; }
[InverseProperty("CreatedBy")]
public List<Contact> ContactsCreated { get; set; }
[InverseProperty("UpdatedBy")]
public List<Contact> ContactsUpdated { get; set; }
}
Works perfectly fine and generated migration on 2.0.0 packages. Please provide a console app reproducing the issue
I'm seeing this same issue in my app too. I'll try to get either a repro or a resolution.
I resolve it https://github.com/aspnet/EntityFrameworkCore/issues/9180#issuecomment-322735278
using Workaround
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity
I am also seeing this error after upgrading to EF 2.0.
Closing as duplicate of #9180 based on comment from @kamleshdelat. @elmojo Does the workaround in #9180 work for you? If not, can you please file a new issue with full project or code listing that reproduces the problem?
@ajcvickers I added the relationship it was complaining about explicitly with Fluent. Of course, it just then complained about the next relationship if found. So yes, the work around would fix my problem but I'd have to spend a long time writing out all the relationships in Fluent. I reverted back to Core 1.1 until #9180 is fixed.
@ajcvickers - Reopening issue to understand if this has same root cause as #9180. In any case of failure to find relationship, fluent API is going to fix it.
@kamleshdelat, @elmojo - Can you share a repro code which demonstrate issue you are facing so we can verify if it has same root cause as #9180
The attached file should reproduce the issue. ef-sample.txt
@elmojo - Thanks for repro code. It is indeed #9180. You can also work-around issue by removing KeyAttribute from your classes.
If the declarative method is now broken and one must use the fluent API, that is an utter fail.
I'll try removing [Key] from my entities. Luckily that is in a base class so that is easy to do.
That may work for some apps, but it can also cause downstream errors. Just tried it on my side. As I have hundreds of such relationship, but a custom written TT file driven by an XML file, I'm going to generate the fluent mappings... but what a pain...
Yeah, it is. I just rolled back for now to 1.1. I'll try the upgrade sometime later. I wasted most of my day running down this issue and reverting. Cannot waste another going back the other way.
Hi @kamleshdelat, @elmojo, and @jbt00000 . We are gathering information on the use of EF Core pre-release builds. You reported this issue shortly after the release of 2.0.0 RTM. It would be really helpful if you could let us know:
- Did you consider testing your code against the pre-release builds?
- Was there anything blocking you from using pre-release builds?
- What do you think could make it easier for you to use pre-release builds in the future?
Thanks in advance for any feedback. Hopefully this will help us to increase the value of pre-release builds going forward.
- We have a tiny dev team, 1.5 people. Tried conversation just before final bits.
- EF identity and JWT breaking changes forced a roll back as we didn’t have time to solve and could not find any migration help faq from those teams.
- You could add an option to build tools whereby on successful unit tests, it would then rebuild with all pre-release packages, and give option for us to send success, compile, unit test errors to makers of those nuget packages who have opted into that feedback.
Sent from my Windows 10 phone
From: Arthur Vickersmailto:[email protected] Sent: Tuesday, September 12, 2017 1:37 PM To: aspnet/EntityFrameworkCoremailto:[email protected] Cc: Jason Thomasmailto:[email protected]; Mentionmailto:[email protected] Subject: Re: [aspnet/EntityFrameworkCore] Unable to determine the relationship represented by navigation property occurring issue after migration of asp.net core 1.1 to 2.0 (#9427)
Hi @kamleshdelathttps://github.com/kamleshdelat, @elmojohttps://github.com/elmojo, and @jbt00000https://github.com/jbt00000 . We are gathering information on the use of EF Core pre-release builds. You reported this issue shortly after the release of 2.0.0 RTM. It would be really helpful if you could let us know:
- Did you consider testing your code against the pre-release builds?
- Was there anything blocking you from using pre-release builds?
- What do you think could make it easier for you to use pre-release builds in the future?
Thanks in advance for any feedback. Hopefully this will help us to increase the value of pre-release builds going forward.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/aspnet/EntityFrameworkCore/issues/9427#issuecomment-328927387, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AX6CL9fmTMeURskgHuAkHfLbfYwPRMkkks5shsFWgaJpZM4O4uSO.
@jbt00000 Thanks for the feedback; much appreciated.
@ajcvickers
We also have a small dev team. I was aware that .NET Core 2.0 was coming out but wasn't following it that closely. When the big announcement was made that 2.0 was released, I decided to give it a try (a major release garners lots of press, a major release preview does not).
Mostly it just came down to lack of awareness of the pre-release builds and lack of time to test it if we were aware of those builds.
The work around or removing the "[Key]" attribute works in our situation and we are now running .NET Core 2.0.
@elmojo Thanks for the feedback; much appreciated.
are this solved in 2.0.1?
@Nickolay-Suslov This issue is marked as a duplicate of #9180 and that issue is marked for fix in 2.1, so no, it's not fixed in 2.0.1.