Starts in:
0 DAY
15 HRS
15 MIN
9 SEC
Starts in:
0 D
15 H
15 M
9 S

Activities of "KittyJuggins"

Note is not an aggregate root, it's a FullAuditedEntity. We need to be able to link user to it. Please can you advise on how we need to actually implement this.

using VideoMarking.Users;
using System;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;
using JetBrains.Annotations;
using Volo.Abp;

namespace VideoMarking.Notes
{
    public class Note : FullAuditedEntity<Guid>, IMultiTenant
    {
        public virtual Guid? TenantId { get; set; }

        [NotNull]
        public virtual string Message { get; set; }
        public Guid? AppUserId { get; set; }

        public AppUser AppUser { get; set; }

        public Note()
        {

        }

        public Note(Guid id, string message)
        {
            Id = id;
            Check.NotNull(message, nameof(message));
            Message = message;
        }
    }
}

Hi,

The AppUser entity looks like:

public class AppUser : FullAuditedAggregateRoot<Guid>, IUser
    {
        #region Base properties

        /* These properties are shared with the IdentityUser entity of the Identity module.
         * Do not change these properties through this class. Instead, use Identity module
         * services (like IdentityUserManager) to change them.
         * So, this properties are designed as read only!
         */

        public virtual Guid? TenantId { get; private set; }

        public virtual string UserName { get; private set; }

        public virtual string Name { get; private set; }

        public virtual string Surname { get; private set; }

        public virtual string Email { get; private set; }

        public virtual bool EmailConfirmed { get; private set; }

        public virtual string PhoneNumber { get; private set; }

        public virtual bool PhoneNumberConfirmed { get; private set; }

        #endregion

        public virtual bool SEN { get; set; }
        public virtual bool PupilPremium { get; set; }
        public virtual bool EAL { get; set; }
        public virtual bool ChildInCare { get; set; }
        public virtual DateTime DateOfBirth { get; set; }
        
        [ForeignKey("School")]
        public Guid? SchoolId { get; set; }

        public virtual School School { get; set; }

        [ForeignKey("Address")]

        public Guid? AddressId { get; set; }

        public virtual Address Address { get; set; }

        [ForeignKey("SchoolYear")]
        public Guid? SchoolYearId { get; set; }

        public virtual SchoolYear SchoolYear { get; set; }

        /* Add your own properties here. Example:
         *
         * public virtual string MyProperty { get; set; }
         * public string MyProperty { get; set; }
         *
         * If you add a property and using the EF Core, remember these;
         *
         * 1. update VideoMarkingDbContext.OnModelCreating
         * to configure the mapping for your new property
         * 2. Update VideoMarkingEfCoreEntityExtensionMappings to extend the IdentityUser entity
         * and add your new property to the migration.
         * 3. Use the Add-Migration to add a new database migration.
         * 4. Run the .DbMigrator project (or use the Update-Database command) to apply
         * schema change to the database.
         */

        private AppUser()
        {
            
        }

The OnModelCreating() method looks like:

protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            /* Configure the shared tables (with included modules) here */


            builder.Entity<AppUser>(b =>
            {
               
                b.ToTable(AbpIdentityDbProperties.DbTablePrefix + "Users"); //Sharing the same table "AbpUsers" with the IdentityUser

                b.Property(p => p.DateOfBirth);
                b.Property(p => p.SEN);
                b.Property(p => p.ChildInCare);
                b.Property(p => p.PupilPremium);
                b.Property(p => p.EAL);

                b.ConfigureByConvention();

                b.ConfigureAbpUser();

                
                /* Configure mappings for your additional properties.
                 * Also see the VideoMarkingEfCoreEntityExtensionMappings class.
                 */
            });

            /* Configure your own tables/entities inside the ConfigureVideoMarking method */

            builder.ConfigureVideoMarking();
        }

The Notes section in DbContextModelCreatingExtensions:

            builder.Entity<Note>(b =>
            {
                b.ToTable(VideoMarkingConsts.DbTablePrefix + "Notes", VideoMarkingConsts.DbSchema);
                b.ConfigureByConvention();
                b.Property(x => x.TenantId).HasColumnName(nameof(Note.TenantId));
                b.Property(x => x.Message).HasColumnName(nameof(Note.Message)).IsRequired();
            });

Yes, its in the ApplicationAutoMapperProfile

As you can see in my previous reply, I have added it in the AutoMapperProfile file already and it still isn't working.

Hi @Alper,

Thanks for the response. I've added that line now, and followed step by step using the example given with the suite, but I am still getting the error

`The property 'AppUser.ExtraProperties' could not be mapped, because it is of type 'Dictionary&lt;string, object&gt;' which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'` on add-migration.

The relevant section of my AutoMapperProfile file looks like:

            CreateMap<AppUser, AppUserDto>().Ignore(x => x.ExtraProperties);

            CreateMap<NoteCreateDto, Note>().IgnoreFullAuditedObjectProperties().Ignore(x => x.Id).Ignore(x => x.TenantId);
            CreateMap<NoteUpdateDto, Note>().IgnoreFullAuditedObjectProperties().Ignore(x => x.Id).Ignore(x => x.TenantId);
            CreateMap<Note, NoteDto>();
            CreateMap<NoteWithNavigationProperties, NoteWithNavigationPropertiesDto>();
            CreateMap<AppUser, LookupDto<Guid?>>().ForMember(dest => dest.DisplayName, opt => opt.MapFrom(src => src.Name));

Please can you advise, Kitty

Showing 1 to 5 of 5 entries
Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06