problem with related fields

Posts   
 
    
ironcross
User
Posts: 31
Joined: 12-May-2006
# Posted on: 01-Jun-2006 13:01:44   

2 week ago i wrote the code like this :

PersonEntity.Employee.Personalid =PersonEntity.PersonId; PersonEntity.Employee.Salary = 1000; PersonEntity.Save(); it worked witohut problem

but now after installing OS i tried to run this code again it didn't work if i move PersonEntity.Employee.Salary = 1000; it didn't display error but Save() is not working i don't know why ? it worked and many peopled worked using this module

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 01-Jun-2006 16:13:17   

Would you please post a complete code snippet from starting from creating/fetching the PersonEntity.

Thanks

ironcross
User
Posts: 31
Joined: 12-May-2006
# Posted on: 06-Jun-2006 08:05:14   

Of cource PersonTableEntity PersonEntity = new PersonTableEntity(); PersonEntity.FirstName = "Klaus"; PersonEntity.LastName = "Meine"; PersonEntity.City = "Hannover"; PersonEntity.Country = "Germany"; PersonEntity.Employee.Personalid = PersonEntity.PersonId; PersonEntity.Employee.Salary = 50000; PersonEntity.Employee.Profession = "Singer"; PersonEntity.Save();

it displays error on personid (field is readonly and can't be changed) if i insert data sequencly to each table it works. but i want to insert using primary key

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 06-Jun-2006 08:14:57   

Try the following:

PersonTableEntity PersonEntity = new PersonTableEntity();
PersonEntity.FirstName = "Klaus";
PersonEntity.LastName = "Meine";
PersonEntity.City = "Hannover";
PersonEntity.Country = "Germany";

EmployeeTableEntity EmployeeEntity = new EmployeeTableEntity();
EmployeeEntity.Salary = 50000;
EmployeeEntity.Profession = "Singer";

PersonEntity.Employee = EmployeeEntity ;
PersonEntity.Save(); 

Please refer to Saving entities recursively & FK-PK synchronization in the LLBLGen Pro manual, under "Using the generated code -> SelfServicing -> Using the entity classes"

ironcross
User
Posts: 31
Joined: 12-May-2006
# Posted on: 06-Jun-2006 09:35:07   

I have tried above mentioned code.but it didn't generates error but it do nothing.

i have changed the code like this.it worked but i want to insert using PK. in doc i can't wind suitable tips. anyway if it works

PersonEntity.FirstName = "Klaus"; PersonEntity.LastName = "Meine"; PersonEntity.City = "Hannover"; PersonEntity.Country = "Germany"; PersonEntity.Save(); EmployeeTableEntity EmployeeEntity = new EmployeeTableEntity(); EmployeeEntity.Salary = 50000; EmployeeEntity.Profession = "Singer"; EmployeeEntity.Personalid= PersonEntity.PersonId; EmployeeEntity.Save();

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 06-Jun-2006 14:25:03   

My mistake, The last line of the code I posted should have been:

PersonEntity.Save(true);

The true boolean parameter tells the save method to save the entire entity graph (recursive save) So the complete code should have been:

PersonTableEntity PersonEntity = new PersonTableEntity();
PersonEntity.FirstName = "Klaus";
PersonEntity.LastName = "Meine";
PersonEntity.City = "Hannover";
PersonEntity.Country = "Germany";

EmployeeTableEntity EmployeeEntity = new EmployeeTableEntity();
EmployeeEntity.Salary = 50000;
EmployeeEntity.Profession = "Singer";

PersonEntity.Employee = EmployeeEntity ;
PersonEntity.Save(true); 

ironcross
User
Posts: 31
Joined: 12-May-2006
# Posted on: 06-Jun-2006 14:43:53   

It generates error(which had generated before) i think it depends on it: it must save primary table first afther that the detail table in this case it does 2 thing in one case,that is why i it generates error

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 06-Jun-2006 15:06:21   

it must save primary table first afther that the detail table in this case it does 2 thing in one case,that is why i it generates error

No it must not, as described here: Saving entities recursively & FK-PK synchronization in the LLBLGen Pro manual, under "Using the generated code -> SelfServicing -> Using the entity classes"

Please post the exact generated error with the stack trace, and the exact code that you are trying to run.

Thanks

ironcross
User
Posts: 31
Joined: 12-May-2006
# Posted on: 06-Jun-2006 15:51:57   

Did you mean this?

See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.


************** Exception Text **************
SD.LLBLGen.Pro.ORMSupportClasses.ORMFieldIsReadonlyException: The field is marked readonly and cannot be changed.
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityField.set_CurrentValue(Object value)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.SyncFKFields(EntitySyncInfoSS syncInfo)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.OnEntityAfterSave(Object sender, EventArgs e)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.FlagAsSaved()
   at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PersistQueue(ArrayList queueToPersist, Boolean insertActions, ITransaction transactionToUse)
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.Save(IPredicate updateRestriction, Boolean recurse)
   at personal_data.EntityClasses.PersonTableEntityBase.Save(IPredicate updateRestriction, Boolean recurse) in C:\Visual C# Samples\personel\EntityBaseClasses\PersonTableEntityBase.cs:line 207
   at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase.Save(Boolean recurse)
   at personal_data.Form1.Add_Click(Object sender, EventArgs e) in C:\Visual C# Samples\personel\Form1.cs:line 66
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

************** Loaded Assemblies **************
mscorlib
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
personal_data
    Assembly Version: 1.0.0.0
    Win32 Version: 1.0.0.0
    CodeBase: file:///C:/Visual%20C%23%20Samples/personel/bin/Debug/personal_data.exe
----------------------------------------
System.Windows.Forms
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
SD.LLBLGen.Pro.ORMSupportClasses.NET20
    Assembly Version: 1.0.2005.1
    Win32 Version: 1.0.20051.060425
    CodeBase: file:///C:/Visual%20C%23%20Samples/personel/bin/Debug/SD.LLBLGen.Pro.ORMSupportClasses.NET20.DLL
----------------------------------------
System.Data
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
SD.LLBLGen.Pro.DQE.Access.NET20
    Assembly Version: 1.0.2005.1
    Win32 Version: 1.0.20051.060423
    CodeBase: file:///C:/Visual%20C%23%20Samples/personel/bin/Debug/SD.LLBLGen.Pro.DQE.Access.NET20.DLL
----------------------------------------
System.Transactions
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.Transactions/2.0.0.0__b77a5c561934e089/System.Transactions.dll
----------------------------------------
System.EnterpriseServices
    Assembly Version: 2.0.0.0
    Win32 Version: 2.0.50727.42 (RTM.050727-4200)
    CodeBase: file:///C:/WINDOWS/assembly/GAC_32/System.EnterpriseServices/2.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll
----------------------------------------

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 06-Jun-2006 16:19:25   

Please use the latest runtime libraries from the customer area. This is an old bug fixed some time ago. If you already use the latest runtime libraries, please let me know.

Frans Bouma | Lead developer LLBLGen Pro
ironcross
User
Posts: 31
Joined: 12-May-2006
# Posted on: 07-Jun-2006 08:48:02   

I have not purchased this product yet.but if you didn't buy this product can you update libraries for demo use?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39928
Joined: 17-Aug-2003
# Posted on: 07-Jun-2006 10:53:22   

If you're a demo-user, you're already having this bugfix, so it's something else. I think I know what it is: Please check if Employee PK is an identity field or readonly in the entity editor (project explorer in llblgen pro designer -> rightclick Employee -> Edit properties, then go to Fields tab and check if there are any readonly fields there. If the FK field of the relation employee - person is readonly, it will never work as the PK value of person is synced with the FK field in employee. The FK field in employee can't be an identity field IF the FK field is the PK of employee, as it gets its value from person.

Frans Bouma | Lead developer LLBLGen Pro