Closed James00-Fast closed 2 years ago
Simple table layout example.
Sorry for the error! In class Common_Status, change the PK to also be the enum as below:
// Status
public class Common_Status
{
public StatusTest StatusId { get; set; } // StatusId (Primary key) <<<========== now an enum
public string Description { get; set; } // Description (length: 50)
// Reverse navigation
/// <summary>
/// Child Common_TestAbcs where [TestABC].[StatusId] point to this entity (FkNameAbc)
/// </summary>
public virtual ICollection<Common_TestAbc> Common_TestAbcs { get; set; } // TestABC.FkNameAbc
public Common_Status()
{
Common_TestAbcs = new List<Common_TestAbc>();
}
}
I will mention this case when the fix is in.
SQL to generate tables above:
CREATE TABLE Common.[Status]
(
StatusId INT IDENTITY(1, 1) NOT NULL,
[Description] NVARCHAR(50) NOT NULL,
CONSTRAINT PK_Status
PRIMARY KEY CLUSTERED (StatusId ASC)
);
GO
CREATE TABLE Common.TestABC
(
TestABCId INT IDENTITY(1, 1) NOT NULL,
StatusId INT NOT NULL,
FieldA VARCHAR(1) NULL,
FieldB BIT NULL,
CONSTRAINT PK_TestABC
PRIMARY KEY CLUSTERED (TestABCId ASC),
CONSTRAINT FkNameAbc
FOREIGN KEY (StatusId)
REFERENCES common.[Status] (StatusId)
);
GO
INSERT INTO Common.[Status] ([Description])
VALUES ('Ok'),('Info'),('Warning'),('Error'),('Critical');
GO
@sjh37 Thank you very much ! Your fast response and effort is appreciated. This worked for us. Added an extra enumDefinitions liked you mentioned 🙌.
Now released in 3.6.1
Has anyone experienced this issue ?
The relationship from 'Common_TestABC.Common_Status' to 'Common_Status.Common_TestAbcs' with foreign key properties {'StatusId' : StatusTest} cannot target the primary key {'StatusId' : int} because it is not compatible. Configure a principal key or a set of foreign key properties with compatible types for this relationship.
We are trying to generate a class from SQL. The table TestABC has a foreign key reference called StatusId to the Status table. Every time we startup the solution we receive the above error. This happens for any table we attempt. The idea is to be able to use the generation in a way TestABC.StatusId = Status (Enum). Rather than creating our own Enums by hand.
I have, among others, tried EnumerationSettings & enumDefinitions. Running out of options. The .tt looks fine. Is this a known issue ?