Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Why is foreign key not set?
 

Pages: 1
LLBLGen Pro Runtime Framework
Why is foreign key not set?
Page:1/1 

  Print all messages in this thread  
Poster Message
Ian
User



Location:
Hertfordshire, UK
Joined on:
01-Apr-2005 16:37:36
Posted:
511 posts
# Posted on: 12-Sep-2017 15:44:40.  
I have

Code:
guestEntity.GuestAccount = new AccountEntity()
{
IsNew = true
};


When guestEntity is recursively saved, the database complains that its property GuestAccountId is null.

Given that I've set the object, shouldn't LLBLGen automatically update the key field?

guestEntity in this instance is new too.
  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37869 posts
# Posted on: 12-Sep-2017 15:54:21.  
https://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=7722

also, why setting isnew to true in accountentity ? It's a new entity instance, so that's set by default.

Anyway, if AccountEntity doesn't have an identity PK, it won't be saved as it's not 'dirty' so nothing is synced as there's nothing to sync


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Ian
User



Location:
Hertfordshire, UK
Joined on:
01-Apr-2005 16:37:36
Posted:
511 posts
# Posted on: 12-Sep-2017 16:01:11. Goto attachments  
yes, I was going to remove isNew once its working.

The model looks ok. I've attached a screen shot.

  Top
Ian
User



Location:
Hertfordshire, UK
Joined on:
01-Apr-2005 16:37:36
Posted:
511 posts
# Posted on: 12-Sep-2017 16:12:26.  
Designer: 3.5 Final
Runtime: 3.5.0.0
Stack:
Quote:
at SD.LLBLGen.Pro.ORMSupportClasses.ActionQuery.Execute()
at SD.LLBLGen.Pro.ORMSupportClasses.BatchActionQuery.Execute()
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.ExecuteActionQuery(IActionQuery queryToExecute)
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.PersistQueue(List`1 queueToPersist, Boolean insertActions, Int32& totalAmountSaved)
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.SaveEntity(IEntity2 entityToSave, Boolean refetchAfterSave, IPredicateExpression updateRestriction, Boolean recurse)
at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.SaveEntity(IEntity2 entityToSave, Boolean refetchAfterSave, Boolean recurse)
at JGSR.BFWeekender.LLBLGenDataAccess.Shared.SharedGenericRepository.SaveEntity(IEntity2 entity, Boolean refretch) in C:\Users\ian\Documents\Source\Commerce\Projects\Websites\Commerce\JGSR.BFWeekender.LLBLGenDataAccess\Shared\SharedGenericRepository.cs:line 13
at JGSR.BFWeekender.BusinessServices.AccountService.UpdateGuest(GuestEntity guestEntity) in C:\Users\ian\Documents\Source\Commerce\Projects\Websites\Commerce\JGSR.BFWeekender.Domain\AccountService.cs:line 34
at JGSR.BFWeekender.Web.group.raver.btnSubmit_OnClick(Object sender, EventArgs e) in C:\Users\ian\Documents\Source\Commerce\Projects\Websites\Commerce\JGSR.BFWeekender.Web\account\guest.aspx.cs:line 119


DB: Sql Server 13.0.4001

Guest is a contact, guest has an account parent and a single guest account.

Profiler shows foreign key isn't set at all...

Code:
exec sp_executesql N'INSERT INTO [mydb].[dbo].[tbl_guest] ([GuestID], [AccountID], [Ordinal]) VALUES (@p13, @p14, @p15)',N'@p13 int,@p14 int,@p15 int',@p13=45749,@p14=17298,@p15=1



  Top
Ian
User



Location:
Hertfordshire, UK
Joined on:
01-Apr-2005 16:37:36
Posted:
511 posts
# Posted on: 12-Sep-2017 16:34:03.  
aha, so it works if I set a property on Account, which I should have added anyway.

Code:
guestEntity.GuestAccount = new AccountEntity { EticketRef = Guid.NewGuid().ToString() };


LLBLGen won't save the Account at all if I don't set the property.
  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14585 posts
# Posted on: 12-Sep-2017 18:41:17.  
True.

  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37869 posts
# Posted on: 12-Sep-2017 20:51:33.  
If it has an identity PK it should be saved, but that wasn't always the case, tho I think on 3.5 that was already implemented. If it doesn't have a pk which is an identity it isn't saved indeed.
Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.