ConstructFilterForUCxxx not created

Posts   
 
    
clint
User
Posts: 145
Joined: 15-Nov-2005
# Posted on: 22-Mar-2021 16:54:43   

Using LLBLGen Designer 5.6.1. Using LLBLGen Runtime Framework.

I've got a table that with a unique key constraint and LLBLGen won't generate a *ConstructFilterForUCxxx *method for it. The Unique Key Constraint is on field PetLicenseId:

CREATE TABLE [dbo].[PetLicenseCaTransactionMap](
    [Id] [int] IDENTITY(1,1) NOT NULL,
    [PetLicenseId] [int] NOT NULL,
    [CaTransactionId] [int] NOT NULL,
    [LineItemGroupNumber] [int] NOT NULL,
    [CreateById] [int] NULL,
    [CreateTime] [dbo].[CreateTime] NULL,
    [UpdateById] [int] NULL,
    [UpdateTime] [dbo].[UpdateTime] NULL,
 CONSTRAINT [PK_PetLicenseCaTransactionMap] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [IX_PetLicenseCaTransactionMap_UniqueKey] UNIQUE NONCLUSTERED 
(
    [PetLicenseId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

*PetLicenseId *is also used as a foreign key:

ALTER TABLE [dbo].[PetLicenseCaTransactionMap]  WITH CHECK ADD  CONSTRAINT [FK_PetLicenseCaTransactionMap_PetLicense] FOREIGN KEY([PetLicenseId])
REFERENCES [dbo].[PetLicense] ([Id])
ON UPDATE CASCADE
ON DELETE CASCADE
GO

The Catalog Explorer in the LLBLGen Designer displays the Unique Key Constraint.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 22-Mar-2021 17:27:39   

The unique constraint is used in the 1:1 relationship formed by thet FK field (making it a 1:1 relationship, otherwise it would have been a m:1 relationship). As this is the case, there's no method to generate this predicate as the UC isn't used as a surrogate key but to make the relationship 1:1.

Frans Bouma | Lead developer LLBLGen Pro
clint
User
Posts: 145
Joined: 15-Nov-2005
# Posted on: 22-Mar-2021 18:50:33   

The PetLicenseCaTransactionMap table is supposed to be a mapping between a PetLicenseand a CaTransaction. It has foreign keys to both the PetLicense and CaTransaction tables.

We want to allow a CaTransaction to be associated with many different PetLicenses, but we want a particular PetLicense to be associated with only one CaTransaction. That's why I created PetLicenseCaTransactionMap.IX_PetLicenseCaTransactionMap_UniqueKey to just use PetLicenseId.

What I'm confused about is that I have a similar table that was made years ago called DocumentTransactionMap that is basically the same as PetLicenseCaTransactionMapexcept that it points to the Document table instead of the PetLicense table. In that table, DocumentId is also both a foreign key and a unique key constraint. LLBLGen generated a DocumentTransactionMapEntity.ConstructFilterForUCDocumentId() method for that.

I'm not understanding why it generated the UC filter for DocumentTransactionMap but not for PetLicenseCaTransactionMap since the tables are pretty much the same. Am I missing something obvious?

CREATE TABLE [dbo].[DocumentTransactionMap](
    [DocumentTransactionMapID] [int] IDENTITY(1,1) NOT NULL,
    [DocumentID] [int] NOT NULL,
    [CaTransactionID] [int] NOT NULL,
    [LineItemGroupNumber] [int] NOT NULL,
    [UpdatedUserID] [varchar](10) NOT NULL,
    [UpdatedTimeStamp] [varchar](14) NOT NULL,
 CONSTRAINT [PK_DocumentTransactionMap] PRIMARY KEY CLUSTERED 
(
    [DocumentTransactionMapID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [IX_DocumentTransactionMap_UniqueKey1] UNIQUE NONCLUSTERED 
(
    [DocumentID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO


ALTER TABLE [dbo].[DocumentTransactionMap]  WITH NOCHECK ADD  CONSTRAINT [FK_DocumentTransactionMap_CaTransaction] FOREIGN KEY([CaTransactionID])
REFERENCES [dbo].[CaTransaction] ([CaTransactionID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[DocumentTransactionMap] CHECK CONSTRAINT [FK_DocumentTransactionMap_CaTransaction]
GO

ALTER TABLE [dbo].[DocumentTransactionMap]  WITH NOCHECK ADD  CONSTRAINT [FK_DocumentTransactionMap_Document] FOREIGN KEY([DocumentID])
REFERENCES [dbo].[Document] ([DocumentID])
ON UPDATE CASCADE
ON DELETE CASCADE
GO

ALTER TABLE [dbo].[DocumentTransactionMap] CHECK CONSTRAINT [FK_DocumentTransactionMap_Document]
GO

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 22-Mar-2021 22:49:34   

Could you please do the following test: create a new LLBLGen Project, and map the same schema and see if you get the method generated for any of these tables? Just to eliminate any possibility of old code files.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39590
Joined: 17-Aug-2003
# Posted on: 23-Mar-2021 10:23:14   

Additionally, could you check if the DocumentTransactionMap - Document relationship is 1:1 or m:1 ? If that relationship was changed to be m:1, the UC is 'unused' for a relationship and is therefore showing up in the list of UCs to generate the method for.

Frans Bouma | Lead developer LLBLGen Pro
clint
User
Posts: 145
Joined: 15-Nov-2005
# Posted on: 23-Mar-2021 23:26:39   

I made a new project as Walaa suggested.

In the old project: LLBLGen designer says: PetLicenseCaTransactionMap.PetLicense - PetLicense.CaTransactionMap (m:1) DocumentTransactionMap.Document - Document.DocumentTransactionMap (1:1)

In the new project: LLBLGen designer says: PetLicenseCaTransactionMap.PetLicense - PetLicense.CaTransactionMap (1:1) DocumentTransactionMap.Document - Document.DocumentTransactionMap (1:1)

So the new project is doing what I expected for the PetLicense - CaTransactionMap relationship.

The part I didn't tell you is this: The PetLicenseCaTransactionMap table used to have a UniqueKey Constraint consisting of: CaTransactionId PetLicenseId

But then I changed it to just use: PetLicenseId

That is when I started having trouble. When I did Sync Relational Data Model , the LLBLGen designer saw that the UniqueKey changed, so it said it removed it from the model (or something like that). But it seems like it never knew the new UniqueKey definition. It never generated a PetLicenseCaTransactionMapEntity.ConstructFilterForUCPetLicenseId() method.

So, I tried syncing again to see if it would add the unique key and create the UC filter. It did not.

So, I tried deleting the *PetLicenseCaTransactionMapEntity * from the project, sync again, reverse-engineer to entity definitions. It still didn't work.

Then I cheated and just changed the XML for this project so both the Entity and table information showed what it should be. That generated the code I wanted. LOL!

But then a co-worker made a database change and resynced which undid my changes.

Then I posted this thread looking for help.

Fixed It! Well, just now, I deleted the PetLicenseCaTransactionMapEntity from the project.
Then I synced, but I unselected the PetLicenseCaTransactionMap table. Then I saved. Then I synced again, and selected the PetLicenseCaTransactionMap table. Then I reverse-engineered to an entity. Now the PetLicenseCaTransactionMap - PetLicense relationship says 1:1. The PetLicenseCaTransactionEntity.ConstructFilterForUCPetLicenseId() was made.

Edit: How come my postings aren't always showing the line breaks created by hitting the "enter" key?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 24-Mar-2021 07:13:09   

clint wrote:

Fixed It! Well, just now, I deleted the PetLicenseCaTransactionMapEntity from the project.
Then I synced, but I unselected the PetLicenseCaTransactionMap table. Then I saved. Then I synced again, and selected the PetLicenseCaTransactionMap table. Then I reverse-engineered to an entity. Now the PetLicenseCaTransactionMap - PetLicense relationship says 1:1. The PetLicenseCaTransactionEntity.ConstructFilterForUCPetLicenseId() was made.

Good you figured it out. It's also useful to take a look at the Unique constraints follow db unique constraints Project Setting. It may be that you started with that setting as true, then all the UC synced fine, then somebody changed it to false. (Ref...)

clint wrote:

Edit: How come my postings aren't always showing the line breaks created by hitting the "enter" key?

This is a known issue planned to be fixed soon simple_smile

David Elizondo | LLBLGen Support Team