Mapping problems in Microsoft.EntityFrameworkCore

1

I'm trying to create two Mappings in ManyToOne using annotation of Entity Framework , however I'm not getting it, if I take either of the two mappings and leave the other, it works however if I leave both of the error. The project is being done in C # in visual studio, the project type is UWP (Universal Windows Platform). I am using MicrosoftEntityFrameworkCore.Sqlite version 1.1.0 The database I am modeling is SQLite.

This is the error message I get:

System.InvalidOperationException: Unable to determine the relationship represented by navigation property 'Sentence.FirstTerm' of type 'Term'. Either manually configure the relationship, or ignore this property from the model.
   em Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.PropertyMappingValidationConvention.Apply(InternalModelBuilder modelBuilder)
   em Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnModelBuilt(InternalModelBuilder modelBuilder)
   em Microsoft.EntityFrameworkCore.Metadata.Internal.Model.Validate()
   em Microsoft.EntityFrameworkCore.Metadata.Internal.InternalModelBuilder.Validate()
   em Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
   em Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.<>c__DisplayClass14_0.<GetModel>b__0(Object k)
   em System.Collections.Concurrent.ConcurrentDictionary'2.GetOrAdd(TKey key, Func'2 valueFactory)
   em Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.GetModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
   em Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
   em Microsoft.EntityFrameworkCore.Internal.LazyRef'1.get_Value()
   em Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_Model()
   em Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServiceCollectionExtensions.<>c.<AddEntityFramework>b__0_6(IServiceProvider p)
   em Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactoryService(FactoryService factoryService, ServiceProvider provider)
   em Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor'2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   em Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitScoped(ScopedCallSite scopedCallSite, ServiceProvider provider)
   em Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor'2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   em Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider)
   em Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   em Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
   em Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.<>c__DisplayClass6_0.<ConfigureContextServices>b__9(IServiceProvider _)
   em Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitFactoryService(FactoryService factoryService, ServiceProvider provider)
   em Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor'2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   em Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProvider provider)
   em Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor'2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   em Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, ServiceProvider provider)
   em Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor'2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   em Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitTransient(TransientCallSite transientCallSite, ServiceProvider provider)
   em Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor'2.VisitCallSite(IServiceCallSite callSite, TArgument argument)
   em Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass16_0.<RealizeService>b__0(ServiceProvider provider)
   em Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
   em Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
   em Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
   em Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
   em Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
   em Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_1.<.ctor>b__0()
   em Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0'1.<Execute>b__0()
   em Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Unable to determine the relationship represented by navigation property 'Sentence.FirstTerm' of type 'Term'. Either manually configure the relationship, or ignore this property from the model.

This is my Term class:

namespace Test.Entity
{
    public class Term
    {
        public Term() {
            FirstTerms = new List();
            LastTerms = new List();
        }
        [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        protected int id;

        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        [InverseProperty("FirstTerm")]
        public virtual ICollection FirstTerms { get; set; }

        [InverseProperty("LastTerm")]
        public virtual ICollection LastTerms { get; set; }
    }
}

This is my class Sentence:


namespace Test.Entity
{
    public class Sentence : Term
    {
        [ForeignKey("Rule")]
        public int RuleId { get; set; }
        public Rule Rule { get; set; }

        [ForeignKey("Operation")]
        public int OperationId { get; set; }
        public Operation Operation { get; set; }

        [ForeignKey("FirstTerm")]
        public int FirstTermId { get; set; }
        public virtual  Term FirstTerm { get; set; }
        [ForeignKey("LastTerm")]
        public int LastTermId { get; set; }
        public virtual Term LastTerm { get; set; }
    }
}

This is my context class (there is more content in it, but none of it refers to the Term or Sentence class):

 protected override void OnModelCreating(ModelBuilder modelBuilder) {
            modelBuilder.Entity().HasIndex(r => r.FirstTermId);
            modelBuilder.Entity().HasIndex(r => r.LastTermId);

        }

The error appears when I run the command:

  

Add-Migration Vanilla

If in class Sentence I remove LastTerm and leave FirstTerm or even remove FirstTerm and leave LastTerm Migration run without error.

References to my project:

How do I solve this problem?

    
asked by anonymous 07.01.2017 / 10:34

0 answers