Target-Per-Entity Key synch..

Posts   
 
    
Posts: 22
Joined: 20-Sep-2006
# Posted on: 13-Oct-2006 20:19:34   

I'm sure this is something rather easy, but this is the first time I'm trying to do a save like this. I have a Customer Table and an Entity Table 1:1 EntityID as PK (int, identity) Customer

I have a type Customer that is a sub-type of Entity.

So I update my customer fields (that include entity fields)


           CustomerEntity _customer = new CustomerEntity();
            _customer.Name = _name;
            _customer.CustomerCode = "001"; //from Customer table
            _customer.IsActive = _isActive;  //From Entity table
            _customer.CrtdUser = _lastUpdate_User; //from entity Table
            _customer.UId = Guid.NewGuid(); //from Entity Table

            _adapter.Save(_customer, true);


So the way I understand it. this should Update the supertype (Entity with the Entity information) and then update the Sub-Type with the PK of the supertype.

It's failing saying that you can't insert NULL into the field EntityID in table customer. I looked at the generated SQL



declare @p3 int
set @p3=8
exec sp_executesql N'INSERT INTO [MyDB].[dbo].[Entity] ([Crtd_User], [LastUpdate_User], [IsActive], [uID])  VALUES (@CrtdUser, 
@LastUpdateUser, @IsActive, @UId);SELECT @EntityId=SCOPE_IDENTITY()',N'@EntityId int output,@CrtdUser varchar(50),@LastUpdateUser 
varchar(50),@IsActive bit,@UId uniqueidentifier',@EntityId=@p3 
output,@CrtdUser='ME',@LastUpdateUser='ME',@IsActive=1,@UId='668AB43D-76D8-4EB2-89B7-DFB550D3FD75'
select @p3

The above statement works correctly, the second statement fails



declare @p4 int
set @p4=NULL
exec sp_executesql N'INSERT INTO [MyDB].[dbo].[Customer] ([CustomerCode], [Name])  VALUES (@CustomerCode, 
 @Name);SELECT @CustomerId=SCOPE_IDENTITY()',N'@CustomerCode varchar(15),@CustomerId int output,@Name 
varchar(50)',@CustomerCode='001',@CustomerId=@p4 output,@Name='1'
select @p4


This statement fails, and you'll notice that it never attempts to insert anything into the CustomerID field.

I'm sure I'm missing something simple here, is there a section in the manual that describes insert process for Sub-Types?

EDIT:

I just tried this with another Entity and it works, that one has the same Field Name as the PK in Entity (EntityID) Example Table Entity (EntityID PK), Table Vendor EntityID(PK,FK). Do I have to make them the same name (i.e. EntityID) for the Synch to occur?

TIA,

Justin

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39616
Joined: 17-Aug-2003
# Posted on: 13-Oct-2006 20:42:07   

I don't understand exactly how the customer - entity table structure is. Entity is the supertype? If so, the pk of THAT entity should be identity, NOT pk of customer, because the pk of customer is an FK to the pk of entity. (at least it should wink )

Frans Bouma | Lead developer LLBLGen Pro
Posts: 22
Joined: 20-Sep-2006
# Posted on: 13-Oct-2006 21:05:09   

Otis wrote:

I don't understand exactly how the customer - entity table structure is. Entity is the supertype? If so, the pk of THAT entity should be identity, NOT pk of customer, because the pk of customer is an FK to the pk of entity. (at least it should wink )

Yes that's exactly how it is.

Table Entity

EntityID (PK, Identity())

Table Customer

CustomerID (PK, FK)

This is 1:1 with the EntityID

Just in case you missed it, I edited the last post to say that it worked with another table the only difference between the two is that the FK column in the (Vendor) other table was named the same as the PK in the Entity table (EntityID)

I hope this makes sense.

Posts: 22
Joined: 20-Sep-2006
# Posted on: 13-Oct-2006 21:26:02   

Well I found the problem. In the LLBLGen Desiger, it still had old schema information for that table which is odd becuse it's been updated several times. This isn't the first time it hasn't grabbed all the changes, perhaps this is by design I'm not sure. This partcular entity is associated with a Typed List and that could be why it it didn't update?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39616
Joined: 17-Aug-2003
# Posted on: 13-Oct-2006 22:32:54   

No, every entity gets updated, it has to simple_smile . So that's not it. Glad it's solved though. If you run into this again, (that info isn't updated) please let us know so we can try to setup a repro case and check whether a bug needs to be squashed simple_smile

Frans Bouma | Lead developer LLBLGen Pro