hitasp
hitasp

Reputation: 726

Why AutoMapper [IgnoreMap] Not working in my project EF Core 2.0

I just started my frist Asp.Net Core project. I want using Many-to-Many ef relations but I getting pmc Error :

`Unable to determine the relationship represented by navigation property 'Category.Brands' of type 'ICollection'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.

So I used[IgnoreMap]` for my entity collections but getting some error.

PM> add-migration "Catalog_Test"
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
      User profile is available. Using 'C:\Users\cs-beginner\AppData\Local\ASP.NET\DataProtection-Keys' as key repository and Windows DPAPI to encrypt keys at rest.
Application startup exception: System.InvalidOperationException: Unable to determine the relationship represented by navigation property 'Category.Brands' of type 'ICollection<Brand>'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.
   at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.PropertyMappingValidationConvention.Apply(InternalModelBuilder modelBuilder)
   at 
.....


   public class Brand : EntityBase
    {
        public string Name { get; set; }

        public string SeoTitle { get; set; }

        [StringLength(5000)]
        public string Description { get; set; }

        public bool IsPublished { get; set; }

        public bool IsDeleted { get; set; }

        public Media ThumbnailImage { get; set; }

        public Guid? ThumbnailImageId { get; set; }

        [IgnoreMap]
        public ICollection<Category> Categories { get; } = new List<Category>();
    }


public class Category : EntityBase
{
    public string Name { get; set; }

    public string SeoTitle { get; set; }

    [StringLength(5000)]
    public string Description { get; set; }

    public int DisplayOrder { get; set; }

    public bool IsPublished { get; set; }

    public bool IncludeInMenu { get; set; }

    public bool IsDeleted { get; set; }

    public Guid? ParentId { get; set; }

    public Category Parent { get; set; }

    [IgnoreMap]
    public ICollection<Category> Children { get; protected set; } = new List<Category>();

    public Media ThumbnailImage { get; set; }

    public Guid? ThumbnailImageId { get; set; }

    [IgnoreMap]
    public ICollection<Brand> Brands { get; protected set; } = new List<Brand>();
}

```

Any idea please? I'm student.

Upvotes: 1

Views: 2682

Answers (1)

Ilya Chernomordik
Ilya Chernomordik

Reputation: 30205

Well, it says to use NotMapped attribute and you used IgnoreMap, maybe that's the problem?

Upvotes: 2

Related Questions