logo
down
shadow

EF Unable to determine the relationship represented by navigation property


EF Unable to determine the relationship represented by navigation property

By : user2173045
Date : October 21 2020, 08:10 PM
I hope this helps you .
The code works fine if i remove DbQuery but i want it there so i can Query on that data without doing an Include from a workflow, and still be sure that no changes are made directly inside the step.
code :


Share : facebook icon twitter icon
Unable to determine the relationship represented by navigation property ASP.NET core 2.0 Entity Framework

Unable to determine the relationship represented by navigation property ASP.NET core 2.0 Entity Framework


By : Huynh Nam Truong
Date : November 21 2020, 03:00 PM
I hope this helps . As what I commented earlier that there are many differences between Entity Framework and Entity Framework Core 2.0, I don't think you can just take the models generated from Entity Framework and run Code First with Entity Framework Core 2.0.
From the models described, it looks like MessageMeta and EnumMeta has many-to-many relationship.
code :
using System.Collections.Generic;

namespace DL.SO.MessageEnum.Web.UI.Models
{
    public class MessageMeta
    {
        public int MsgId { get; set; }

        public List<MessageEnum> EnumMetas { get; set; }
    }
}
using System.Collections.Generic;

namespace DL.SO.MessageEnum.Web.UI.Models
{
    public class EnumMeta
    {
        public int EnumId { get; set; }
        public bool IsFlag { get; set; }

        public List<MessageEnum> MessageMetas { get; set; }
    }
}
namespace DL.SO.MessageEnum.Web.UI.Models
{
    public class MessageEnum
    {
        public int MessageMetaId { get; set; }
        public MessageMeta MessageMeta { get; set; }

        public int EnumMetaId { get; set; }
        public EnumMeta EnumMeta { get; set; }
    }
}
using Microsoft.EntityFrameworkCore;

namespace DL.SO.MessageEnum.Web.UI.Models
{
    public class AppDbContext : DbContext
    {
        public AppDbContext(DbContextOptions<AppDbContext> options): base(options) { }

        public DbSet<MessageMeta> Messages { get; set; }
        public DbSet<EnumMeta> Enums { get; set; }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<MessageMeta>()
                .HasKey(x => x.MsgId);

            modelBuilder.Entity<EnumMeta>()
                .HasKey(x => x.EnumId);

            modelBuilder.Entity<MessageEnum>()
                .HasKey(x => new { x.MessageMetaId, x.EnumMetaId });
            modelBuilder.Entity<MessageEnum>()
                .HasOne(x => x.MessageMeta)
                .WithMany(m => m.EnumMetas)
                .HasForeignKey(x => x.MessageMetaId);
            modelBuilder.Entity<MessageEnum>()
                .HasOne(x => x.EnumMeta)
                .WithMany(e => e.MessageMetas)
                .HasForeignKey(x => x.EnumMetaId);
        }
    }
}
{
  "ConnectionStrings": {
    "AppDbConnection": "Data Source=.\\SQLEXPRESS;Initial Catalog=SO.MessageEnum;Integrated Security=True;MultipleActiveResultSets=False;"
  },
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  }
}
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using DL.SO.MessageEnum.Web.UI.Models;
using Microsoft.EntityFrameworkCore;

namespace DL.SO.MessageEnum.Web.UI
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            string dbConnectionString = Configuration.GetConnectionString("AppDbConnection");

            services.AddDbContext<AppDbContext>(options =>
                options.UseSqlServer(dbConnectionString)
            );

            services.AddMvc();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
    }
}
Add-Migration Init
Update-Database
Unable to determine the relationship represented by navigation property

Unable to determine the relationship represented by navigation property


By : nunny
Date : March 29 2020, 07:55 AM
this will help As explained in this answer, I would need to duplicate the shared relationships.
When using DbContext2, the relationships between User and Group aren't defined.
How to fix 'Unable to determine the relationship represented by navigation property' error in Entity Framework

How to fix 'Unable to determine the relationship represented by navigation property' error in Entity Framework


By : Jiganesh Ganda Lal
Date : March 29 2020, 07:55 AM
hope this fix your issue When I try to register a user on my .NET Core 2.1 website (using identity) I get the following error: , UPDATE
You have multiple options here:
code :
public partial class City
{
    public City()
    {           
        Connections = new HashSet<Connection>();
    }

    public int Id { get; set; }
    public string Name { get; set; }
    public string Country { get; set; }

    public ICollection<Connection> Connections { get; set; }
}
public partial class Connection
{
    public Connection()
    {
    }

    public int Id { get; set; }

    public int StartCityId { get; set; }
    public int EndCityId { get; set; }

    public int AantalMinuten { get; set; }
    public double Prijs { get; set; }     
}
modelBuilder.Entity<City>().HasMany(city => city.Connections)
                           .WithRequired().HasForeignKey(con => con.EndCityId);

modelBuilder.Entity<City>().HasMany(city => city.Connections)
                           .WithRequired().HasForeignKey(con => con.StartCityId);
public partial class City
{
    public City()
    {           
        Connections = new HashSet<Connection>();
    }

    public int Id { get; set; }
    public string Name { get; set; }
    public string Country { get; set; }

    public ICollection<Connection> Connections { get; set; }
}
public partial class Connection
{
    public Connection()
    {
    }

    public int Id { get; set; }

    public virtual ICollection<City> Cities { get; set; }

    public int AantalMinuten { get; set; }
    public double Prijs { get; set; }     
}
Unable to determine the relationship represented by navigation property 'JToken.Parent' of type 'JContainer'

Unable to determine the relationship represented by navigation property 'JToken.Parent' of type 'JContainer'


By : user2831730
Date : March 29 2020, 07:55 AM
I wish this helpful for you I finally found that by myself. As the error message has mentioned, I should add a [NotMapped] attribute before the properties which is not in my table fields.
EF Core unable to determine relationship represented by foreign keys in abstract class

EF Core unable to determine relationship represented by foreign keys in abstract class


By : PoHsiang
Date : March 29 2020, 07:55 AM
With these it helps
A potential additional complication is that the User class also has a property of class Department, which is unrelated to the CreatedBy and ModifiedBy properties on Department.
code :
modelBuilder.Entity<User>()
    .HasOne(e => e.Department)
    .WithMany();

modelBuilder.Entity<Department>()
    .HasOne(e => e.CreatedBy)
    .WithMany();

modelBuilder.Entity<Department>()
    .HasOne(e => e.ModifiedBy)
    .WithMany();
Related Posts Related Posts :
  • How do request a correct access token in ASP.NET Core for Azure AD to access Microsoft Graph
  • How to run a .NET Core console application on Linux
  • UI not updating for bound element
  • C# Odata v4 open type raw values
  • DocumentFormat.OpenXml Modify Creator Propery of Document
  • How to SetBasePath in ConfigurationBuilder in Core 2.0
  • ASP MVC5 public readonly variable changes value when it should not
  • How to conditionally select item from hashset with queryable linq?
  • Progress Bar C# not showing the real progress
  • Correct logic to reconnect in SignalR with HubConnection
  • ComboBox with two or more sections
  • .NET listbox to SQLite DB
  • C# Ninject binding from Dictionary<Type, Type>
  • asp.net mvc -view displaying real-time progress status
  • Getting reference to dependent in service with generic type
  • Implementing EqualityCompare vs overriding GetHashCode and Equals
  • C# Linq Find all indexes of item in List<int> within another List<int>
  • XML image how to display at data grid columns in c#.net
  • How to override Equals and GetHash of HashSet
  • Creating Windows authentication and SQL Server authentication in login form
  • How to interop with Azure Service Bus topics created by MassTransit using Rebus?
  • MVC 5 Google Calendar Integration
  • C# - Use parallel arrays to calculate cost of a phone call in GUI
  • Use a int in entire code
  • How to display newly added element at the top of StackPanel in WPF?
  • T4MVC is generating T4MVC.cs and T4MVC1.cs
  • Remove blur effect on certain controls inside UserControl
  • Sql Transcation Query to Linq Query in Wcf Rest Service
  • Setting AWS S3 credentials in C# app
  • does not contain in an ObservableCollection
  • App doesn't run it crashed directly after I started it
  • Is it possible in Entity Framework MVC application to run .sql scripts on a different database
  • Type Inference with Deconstruct tuple assignment extension methods
  • Setting up mock objects for EF dbcontext to test repository methods
  • Using C# in XSLT with MSXSL 6.0
  • Absolute positioning of UIElement in FlowDocument in WPF
  • Display debuggers not showing up in Visual Studio 2017
  • Discord.NET Users playing the same game
  • Azure function output API call to 3rd party service
  • Unable to determine the relationship represented by navigation property ASP.NET core 2.0 Entity Framework
  • Regex to find group of Regex inside a word
  • When calling a method, when to reference the class, and when to reference the object?
  • AmazonCloudWatchLogsClient async methods failing with no error
  • Create FileStream in memory instead of saving a physical file on disk
  • ViewBag data coming from ActionFilter is persisting in session even after database
  • ERROR: the name 'lvSubCategories' does not exist in the current context
  • Why datetime can't recognise the string?
  • Getting 500 error while requesting to webservice using Ajax AutoCompleteExtender
  • The property 'x' is not a navigation property of entity type 'y'
  • ASP.NET MVC - How to generate empty input boxes in loop when model is empty?
  • Need help writing regular expression
  • Add/remove buttons to a panel with an arraylist c#
  • Linq .Where(type = typeof(xxx)) comparison is always false
  • Using EF6 Code First without migrations to an existing db how do I specify column names of the many to many join table?
  • C# - Using Thread.Sleep precisely in a console application
  • Add item to a List<Tuple> inside another list
  • Double[,], inversion C#
  • Counting a string to ensure the input is within a min/max boundary
  • Assign invalidValue to Enum variable (why is this not throwing an Exception?)
  • Namespace or type specified in the project-level Imports 'System.Threading.Tasks' doesn't contain any public member or c
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org