Hi - I'm using .net Core/Jquery v4.0
I have an entity that inherits FullAuditedEntity, meaning the CreatorUserID exists on this entity/table. How do I include the AbpUsers table when pulling data from the repository? Since the CreatorUserID column is not setup as a foreign key to the AbpUsers.Id I'm not sure how to reference it correctly. I'm trying to pull in the username from the AbpUsers table into my entity.
Thanks,
Mike
8 Answer(s)
-
0
For reference here is what I'm using:
I'm subclassing AbpUsers<User> and using the InverseProperty attribute:
public class User : AbpUser<User> { [InverseProperty("CreatorUser")] public ICollection<PMNotes> CreatorNotes { get; set; } [InverseProperty("DeleterUser")] public ICollection<PMNotes> DeleterNotes { get; set; } }
then in the table that I want to reference I'm doing:
[Table("PMNotes")] public class PMNotes : FullAuditedEntity, IMustHaveTenant { public virtual int TenantId { get; set; } public virtual User CreatorUser { get; set; } public virtual User DeleterUser { get; set; } [Required] public virtual string Note { get; set; } }
but i get this error:
Unable to determine the relationship represented by navigation property 'User.DeleterUser' of type 'User'. Either manually configure the relationship, or ignore this property from the model.
-
0
Hi,
Does your scenario works for CreatorUser when you remove DeleterUser InverseProperty ?
Thanks.
-
0
Hi - unfortunately not, I get the following error:
Unable to determine the relationship represented by navigation property 'User.DeleterUser' of type 'User'. Either manually configure the relationship, or ignore this property from the model.
-
0
Hi,
Can you define your entity like this ?
public class PMNotes : FullAuditedEntity<User>, IMustHaveTenant { ... }
You will need to remove CreatorUser and DeletorUser as well.
If it does not work, you can try to configure it manually.
Thanks.
-
0
That breaks the app service:
private readonly IRepository<PMNotes> _notesRepository;
with the error:
The type ...PMNotes can not be used as a type parameter 'TEntity' in the generic type or method IRepository<TEntity>.
what is the manual configuration look like?
-
0
Hi,
Can you change your repository to
private readonly IRepository<PMNotes,User> _notesRepository;
Actually I don't know the manual configuration but you have to do it in OnModelCreating on your DbContext. You can check it on the internet since it is a common thing in EF.
Thanks.
-
0
I got this working where I can now include the AbpUsers table for any AuditedEntity by adding a FK to either CreatorUserId, DeleterUserId, or LastModifierUserId.
Table with CreatorUserId, note that it references Authorization.Users.User instead of subclassing the AbpUsers entity:
[Table("PMNotes")] public class PMNotes : FullAuditedEntity, IMustHaveTenant { public virtual int TenantId { get; set; } ... [ForeignKey("CreatorUserId")] public Authorization.Users.User CreatorUser { get; set; } }
Added the collection to the Authorization.Users.User table:
public class User : AbpUser<User> { public ICollection<PMNotes> CreatorNotes { get; set; } ... }
Then in the DBContext, add the following (although this may not actually be required with the "ForeignKey" attribute above:
modelBuilder.Entity<PMNotes>() .HasOne(m => m.CreatorUser) .WithMany(t => t.CreatorNotes) .HasForeignKey(m => m.CreatorUserId) .OnDelete(DeleteBehavior.Restrict);
Hope it helps someone.
-
0
@MikeyMey01,
Helped a great deal. Thanks for posting..