public void Configure(EntityTypeBuilder <CatalogCategory> builder) { builder .Property(x => x.Id) .UsePropertyAccessMode(PropertyAccessMode.Field) .HasConversion(x => x.Id, id => CatalogCategoryId.Of(id)); builder .Property(x => x.CatalogId) .IsRequired() .HasConversion(x => x.Id, id => CatalogId.Of(id)); builder .Property(x => x.CategoryId) .IsRequired() .HasConversion(x => x.Id, id => CategoryId.Of(id)); builder .HasOne(x => x.Parent) .WithMany() .HasForeignKey("CatalogCategoryParentId") .IsRequired(false); builder.Ignore(x => x.IsRoot); }
private bool CatalogCategoryIsExistingInCatalog(IRepositoryFactory repositoryFactory, CatalogId catalogId, CatalogCategoryId catalogCategoryId) { var repository = repositoryFactory.CreateRepository <Catalog>(); var catalog = repository.FindOneWithIncludeAsync(x => x.CatalogId == catalogId, x => x.Include(c => c.Categories)).GetAwaiter().GetResult(); return(catalog != null && catalog.Categories.Any(x => x.CatalogCategoryId == catalogCategoryId)); }