You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
A generic interface with a primary key generic type parameter used with two different primary key types causes a domain build failure #332
[HierarchyRoot(InheritanceSchema.SingleTable)]
[TableMapping("a_list")]
public sealed class AList : LegacyUserTrackedEntity, ICodebookEntity<short>
{
[Key(0)]
[Field]
[FieldMapping("id_list")]
public short Id { get; set; }
}
[HierarchyRoot(InheritanceSchema.SingleTable)]
[TableMapping("c_system")]
public sealed class CSystem : LegacyUserTrackedEntity, ICodebookEntity<int>
{
[Key]
[Field]
[FieldMapping("id")]
public int Id { get; set; }
}
DataObjects throws this error: Implementors of ICodebookEntity interface belong to hierarchies with different key structure: AList & CSystem.
However, the interfaces are ICodebookEntity<short> and ICodebookEntity<int> — two different things.
I think you have misunderstood the error. The problem is not with generic interface itself. DO counts implementors of ICodeBookEntity and ICookBookEntity separately, and if an interface has more than one implementor then all implementors will be checked for key structure - for number of key fields and for types of those fields.
Any updates on this? Did my answer help to lid a problem with model? Should I dig dipper for this? In this case I need your assistance to reproduce the issue.
Update on when exactly this problem occurs: If the generic interface inherits from a normal interface which in turn inherits from IEntity, then this error occurs. If the generic interface directly inherits from IEntity, then it works.
The following declaration causes the error:
public interface ICodebookEntity : IEntity
{
}
public interface ICodebookEntity<out TKey> : ICodebookEntity
where TKey : struct
{
[Field]
TKey Id { get; }
[Field]
string Code { get; }
[Field]
DateTime DateLastModified { get; }
}
However, when declared as follows, the hierarchy works just fine:
public interface ICodebookEntity
{
}
public interface ICodebookEntity<out TKey> : IEntity, ICodebookEntity
where TKey : struct
{
[Field]
TKey Id { get; }
[Field]
string Code { get; }
[Field]
DateTime DateLastModified { get; }
}
And I've created two tests that build domain with these types in model like so
publicclassIssueGithub0332_GenericIntefaceCausesErrorOnBuild{[Test]publicvoidWorkingCase(){//the factory just creates configuration with connection to test storage environmentvarconfiguration=DomainConfigurationFactory.Create();configuration.UpgradeMode=DomainUpgradeMode.Recreate;configuration.Types.Register(typeof(Models.GoodExample.IntCodeBookEntity));configuration.Types.Register(typeof(Models.GoodExample.LongCodeBookEntity));configuration.Types.Register(typeof(Models.GoodExample.ICodebookEntity));configuration.Types.Register(typeof(Models.GoodExample.ICodebookEntity<>));using(vardomain=Domain.Build(configuration)){}}[Test]publicvoidNotWorkingCase(){//the factory just creates configuration with connection to test storage environmentvarconfiguration=DomainConfigurationFactory.Create();configuration.UpgradeMode=DomainUpgradeMode.Recreate;configuration.Types.Register(typeof(Models.BadExample.IntCodeBookEntity));configuration.Types.Register(typeof(Models.BadExample.LongCodeBookEntity));configuration.Types.Register(typeof(Models.BadExample.ICodebookEntity));configuration.Types.Register(typeof(Models.BadExample.ICodebookEntity<>));using(vardomain=Domain.Build(configuration)){}}}
Both tests have completed successfully.
I also tried not to declare [Field] in classes and tried to move one of non-key fields to non-generic ICodebookEntity interface. Works just fine.
The tests were run on the latest for 7.0 branch version - 7.0.6 version.
Can you guide me to what I should change to have such error as you're getting? Also, if you can, please, verify that your case still doesn't work on v7.0.6.
Activity
alex-kulakov commentedon Aug 15, 2023
Hello @ondrejtucny,
I think you have misunderstood the error. The problem is not with generic interface itself. DO counts implementors of ICodeBookEntity and ICookBookEntity separately, and if an interface has more than one implementor then all implementors will be checked for key structure - for number of key fields and for types of those fields.
Following model I have created works just fine:
I believe that you have various key fields number within each interface.
You can take a look at
dataobjects-net/Orm/Xtensive.Orm/Orm/Building/ModelInspector.cs
Lines 153 to 175 in f598e2a
you can see calling for validation if count is more that 1
and the validation itself
dataobjects-net/Orm/Xtensive.Orm/Orm/Building/Validator.cs
Lines 271 to 297 in f598e2a
alex-kulakov commentedon Sep 6, 2023
Hello @ondrejtucny,
Any updates on this? Did my answer help to lid a problem with model? Should I dig dipper for this? In this case I need your assistance to reproduce the issue.
ondrejtucny commentedon Feb 6, 2025
Update on when exactly this problem occurs: If the generic interface inherits from a normal interface which in turn inherits from
IEntity, then this error occurs. If the generic interface directly inherits fromIEntity, then it works.The following declaration causes the error:
However, when declared as follows, the hierarchy works just fine:
alex-kulakov commentedon Feb 11, 2025
@ondrejtucny,
Thank you for the update, I will re-check and give you my update a bit later.
alex-kulakov commentedon Feb 12, 2025
Hello @ondrejtucny ,
I've created two models according to your latest examples, they look like so
And I've created two tests that build domain with these types in model like so
Both tests have completed successfully.
I also tried not to declare
[Field]in classes and tried to move one of non-key fields to non-genericICodebookEntityinterface. Works just fine.The tests were run on the latest for 7.0 branch version - 7.0.6 version.
Can you guide me to what I should change to have such error as you're getting? Also, if you can, please, verify that your case still doesn't work on v7.0.6.