I extended the existing IdentityUser with the extension system, and also had it mapped to a different column using ef core mapping, which is working fine for the UI side as well
ObjectExtensionManager.Instance.Modules()
.ConfigureIdentity(identity =>
{
identity.ConfigureUser(user =>
{
user.AddOrUpdateProperty<Guid?>(
"ClassroomId",
property =>
{
//property.Attributes.Add(new RequiredAttribute());
//validation rules
property.DisplayName = new FixedLocalizableString("Classroom");
property.UI.Lookup.Url = "/api/app/classrooms";
property.UI.Lookup.DisplayPropertyName = "name";
property.UI.Lookup.FilterParamName = "filterText";
}
);
});
});
ObjectExtensionManager.Instance
.MapEfCoreProperty<IdentityUser, Guid?>(
"ClassroomId",
(entityBuilder, propertyBuilder) =>
{
entityBuilder
.HasOne(typeof(Classroom))
.WithMany()
.HasForeignKey("ClassroomId");
}
);
How to query on that property when querying from database directly and not using client side evaluation?
The doc mentions 'Another approach can be creating your own entity mapped to the same database table (or collection for a MongoDB database).`
Tried by making a class AppUser that inherits from IdentityUser mapped to the same table 'AbpUsers' however that makes a discriminator column, and queries with the new class dont bring out all records, which I think is expected from EF Core TablePerHierarchy.
What's the ideal solution for querying something like this?
var users = await Users.Where(x=> x.GetClassroomId() == classId).ToListAsync();
public static class IdentityUserExtensions
{
private const string ClassroomIdPropertyName = "ClassroomId";
public static void SetClassroomId(this IdentityUser user, Guid? classroomId)
{
user.SetProperty(ClassroomIdPropertyName, classroomId);
}
public static Guid? GetClassroomId(this IdentityUser user)
{
return user.GetProperty<Guid?>(ClassroomIdPropertyName);
}
}
Also I would rather not go for a new New Entity with Its Own Database Table, and using local bus to keep them synchronized, unless its the last option