-
Notifications
You must be signed in to change notification settings - Fork 26
A generic interface with a primary key generic type parameter used with two different primary key types causes a domain build failure #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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: public interface ISomeEntity<TEntityKey> : IEntity
{
[Field]
TEntityKey Id { get; }
[Field]
string Name { get; set; }
[Field]
DateTime CreationDate { get; set; }
}
[HierarchyRoot(InheritanceSchema.SingleTable)]
public sealed class IntImplementor : Entity, ISomeEntity<int>
{
[Field, Key(0)]
public int Id { get; private set; }
[Field]
public string Name { get; set; }
[Field]
public DateTime CreationDate { get; set; }
}
[HierarchyRoot(InheritanceSchema.SingleTable)]
public sealed class LongImplementor : Entity, ISomeEntity<long>
{
[Field, Key]
public long Id { get; private set; }
[Field]
public string Name { get; set; }
[Field]
public DateTime CreationDate { get; set; }
}
[HierarchyRoot(InheritanceSchema.SingleTable)]
public sealed class ShortImplementor : Entity, ISomeEntity<short>
{
[Field, Key(0)]
public short Id { get; private set; }
[Field]
public string Name { get; set; }
[Field]
public DateTime CreationDate { get; set; }
} 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
|
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. |
Update on when exactly this problem occurs: If the generic interface inherits from a normal interface which in turn inherits from The following declaration causes the error:
However, when declared as follows, the hierarchy works just fine:
|
Thank you for the update, I will re-check and give you my update a bit later. |
Hello @ondrejtucny , I've created two models according to your latest examples, they look like so namespace Xtensive.Orm.Tests.Issues.IssueGithub0332_GenericIntefaceCausesErrorOnBuildModel
{
namespace GoodExample
{
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; }
}
public class IntCodeBookEntity : Entity, ICodebookEntity<int>
{
[Field, Key]
public int Id { get; private set; }
[Field]
public string Code { get; set; }
[Field]
public DateTime DateLastModified { get; set; }
}
public class LongCodeBookEntity : Entity, ICodebookEntity<long>
{
[Field, Key]
public long Id { get; private set; }
[Field]
public string Code { get; set; }
[Field]
public DateTime DateLastModified { get; set; }
}
}
namespace BadExample
{
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; }
}
public class IntCodeBookEntity : Entity, ICodebookEntity<int>
{
[Field, Key]
public int Id { get; private set; }
[Field]
public string Code { get; set; }
[Field]
public DateTime DateLastModified { get; set; }
}
public class LongCodeBookEntity : Entity, ICodebookEntity<long>
{
[Field, Key]
public long Id { get; private set; }
[Field]
public string Code { get; set; }
[Field]
public DateTime DateLastModified { get; set; }
}
}
} And I've created two tests that build domain with these types in model like so public class IssueGithub0332_GenericIntefaceCausesErrorOnBuild
{
[Test]
public void WorkingCase()
{
//the factory just creates configuration with connection to test storage environment
var configuration = 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 (var domain = Domain.Build(configuration)) { }
}
[Test]
public void NotWorkingCase()
{
//the factory just creates configuration with connection to test storage environment
var configuration = 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 (var domain = Domain.Build(configuration)) { }
}
} Both tests have completed successfully. I also tried not to declare 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. |
When the following two entities are declared:
DataObjects throws this error: Implementors of
ICodebookEntity
interface belong to hierarchies with different key structure:AList
&CSystem
.However, the interfaces are
ICodebookEntity<short>
andICodebookEntity<int>
— two different things.Using version 7.0.3.
The text was updated successfully, but these errors were encountered: