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

asp.net-core automapper c# entity-framework-core

Question

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.

1
1
2/14/2018 9:10:46 PM

Accepted Answer

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

2
2/14/2018 9:03:57 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow