Is there a way to add a 1:1 relationship between a table and a view?

Posts   
 
    
Posts: 98
Joined: 10-Nov-2006
# Posted on: 02-Jul-2010 01:39:01   

Using: LLBLGen Pro v3.0 Final (June 28th, 2010) SQL 2005

(This is somewhat related to the bug I posted in http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=18189 but I have a different question now ...)

I have a table (Item) that has a PK ItemId. ItemId is generated via the SCOPE_IDENTITY sequence. I also have a SQL view, ItemView (defined as SELECT * FROM Item ...). I've used the designer to mark ItemId as the PK for ItemView, and also mark it as using SCOPE_IDENTITY.

Now, I'd like to add a 1:1 relationship between the view and the table so that I can easily use a Navigator in my code to get from one to the other. That's easily done, using the "New Normal Relationship" dialog. I choose Item's ItemId to be the PK and ItemView's ItemId to be the FK.

Now that I've added that relationship, the validator gives me the error that "SequenceToUse: The field "ItemId (FK)" is a foreign key field and foreign key fields can't have a sequence mapped, as they receive their value from the associated identifying field."

The error makes sense, but this working in v2.6, and I'd like to continue to use this relationship with as little change to my code as possible. Is there a better way I should be doing this?

Thanks.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Jul-2010 06:25:15   

I can't reproduce that with the latest version. Maybe the only thing you should do is remove the SCOPE_IDENTITY from SequenceToUse in the ItemView entity.

David Elizondo | LLBLGen Support Team
Posts: 98
Joined: 10-Nov-2006
# Posted on: 02-Jul-2010 06:31:08   

David,

Thanks for your response.

I'm attaching my project file in the hope that that can help you reproduce the issue. You're right that I could clear out the SequenceToUse field for the ItemView, but I believe that that would make it so that could not create new entities using the ItemView. I could probably work around that, but I'm still wondering if this is a bug, or just something I was getting away with in 2.6?

Attachments
Filename File size Added on Approval
Test.llblgenproj 25,382 02-Jul-2010 06:31.34 Approved
Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 02-Jul-2010 09:59:13   

I haven't checked your project yet.

But definitly you should clear the SequenceToUse from the ItemView. This won't prevent you from doing something like:

var itemView = new ItemViewEntity(10);
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 03-Jul-2010 10:49:15   

Indeed, just remove the sequence in the mappings. In v2.6 it 'worked' but it didn't make any sense. simple_smile

Frans Bouma | Lead developer LLBLGen Pro