Hi, I'm new to IdentityServer 4 so please be patient.
I'm developing a management application for IdentityServer 4 and I ran into a situation where I don't want duplicated ApiProperties (the pair Key/Value) in the database.
To solve this it I'm trying to call the Distinct method on the collection of properties before inserting it into the database.
The thing is that the Equals method is the standard one and it uses the entities reference to compare them.
I tried to inherit a class from ApiResourceProperty and override the equals method, the thing is that I can't use that class with the ConfigurationDbContext, even though the structure is the same as the base one.
I tried to create a new context inherited from ConfigurationDbContext and map the new class to the ApiResources table but apparently it's not possible to override it.
Could you in future releases add an easier way to override the entities, like in Net Core Identity ?
This is the class I was trying to create:
public class ApplicationApiResourceProperty : ApiResourceProperty, IEquatable
{
public bool Equals(ApplicationApiResourceProperty other)
{
return this.Key == other.Key && this.Value == other.Value;
}
public override int GetHashCode()
{
int hashKey = Key == null ? 0 : Key.GetHashCode();
int hashValue = Value == null ? 0 : Value.GetHashCode();
return hashKey ^ hashValue;
}
}
And this is the new Db Context:
public class IdentityServerConfigurationDbContext : ConfigurationDbContext
{
public IdentityServerConfigurationDbContext(DbContextOptions
ConfigurationStoreOptions storeOptions)
: base(options, storeOptions)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<ApplicationApiResourceProperty>().ToTable("ApiProperties");
}
}
Edit; I know I can implement the IEqualityComparer
I ran into the same issue when trying to extend the client with a one-to-one ClientExtended table. I was not able to create a new client (inheriting from client) in order to add a simple nav property to my ClientExtended class due to the IConfigurationDbContext. I too would benefit from some kind of extendable solution. Thanks!
I need to add some properties to the entity models too.
Is the any near plan to have this feature?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Checking if it's being support now to inherit IS4 entities, e.g., Client, ApiResource, ApiScope. Or is it more recommended to use the associated property tables? Or maybe a customized table to denote the relation. Thanks a lot!
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
I need to add some properties to the entity models too.
Is the any near plan to have this feature?