Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Trying to map Many to Many in EF Core

$
0
0

Hi

I am trying to map modela to modelb i have a model ab table, and I have fluent api setup in a different class using IEntityTypeConfiguration

my code looks like

public class ABModelConfiguration : IEntityTypeConfiguration<ABModel>
    {
        public void Configure(EntityTypeBuilder<ABModel> builder)
        {

            

            builder.HasKey(ra => new { ra.AId, ra.BId});

            builder.HasOne(ra => ra.AModel)
                .WithMany(rt => rt.AModels)
                .HasForeignKey(ra => ra.AId);

            builder.HasOne(ra => ra.BModel)
                .WithMany(rt => rt.BModels)
                .HasForeignKey(ra => ra.BId);

        }
    }

howeve under the BModels and AModels in the .WithManyStatement i have a red squigally line saying it cannot convert ICollection To IEnumerable

in the ABModel they are list as single models eg public AModel {get;set;} in the A and B Model they are public ICollection<ABModel> ABModels {get;set;}

I am using .net EF 2.1, and i can't find the answer, any suggestions would be appriciated.


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>