Hi,
I have found what seems to be a bug in 2.6 beta - or at least behaviour that is different from 2.5. I have a newly-created Person entity, which has a ReferringAgent entity linked by their ID fields in a 1:1 relation. I save the Person entity non-recursively, and not refetching from the database. Its Id field is updated to the new identity value, correctly. I then save the related ReferringAgent entity, but this fails with the following exception:
An exception was caught during the execution of an action query: Duplicate entry '0' for key 1. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception.
at SD.LLBLGen.Pro.ORMSupportClasses.ActionQuery.Execute() in F:\Source code\LLBLGen Pro\2.6\Sourcecode\RuntimeLibraries\Net2.x\ORMSupportClasses\Query\ActionQuery.cs:line 197
Inner exception:
"Duplicate entry '0' for key 1"
at CoreLab.MySql.bc.n()
at CoreLab.MySql.bc.c()
at CoreLab.MySql.c.a(f[]& A_0, Int32& A_1)
at CoreLab.MySql.c.a(Byte[] A_0, Int32 A_1, Boolean A_2)
at CoreLab.MySql.ab.e()
at CoreLab.MySql.ab.o()
at CoreLab.MySql.MySqlCommand.a(CommandBehavior A_0, IDisposable A_1, Int32 A_2, Int32 A_3)
at CoreLab.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader()
at CoreLab.Common.DbCommandBase.ExecuteNonQuery()
at SD.LLBLGen.Pro.ORMSupportClasses.ActionQuery.Execute() in F:\Source code\LLBLGen Pro\2.6\Sourcecode\RuntimeLibraries\Net2.x\ORMSupportClasses\Query\ActionQuery.cs:line 168
I can see the cause: the ReferringAgent entity doesn't have its ID set when the Person entity is saved, thus it tries to save a zero in the database, which fails due to FK constraints.
This worked correctly in 2.5. The following code snippet shows a reproduction of my problem:
var person = new PersonEntity();
person.FirstName = "someone";
person.ReferringAgent = new ReferringAgentEntity();
person.ReferringAgent.AffiliateWebsiteFolder = "something";
using (DataAccessAdapter adapter = new DataAccessAdapter())
{
// V2.5: person.Id == 0, person.ReferringAgent.Id == 0
// V2.6: person.Id == 0, person.ReferringAgent.Id == 0
adapter.SaveEntity(person, true, false);
// V2.5: person.Id == 12345, person.ReferringAgent.Id == 12345
// V2.6: person.Id == 12345, person.ReferringAgent.Id == 0
adapter.SaveEntity(person.ReferringAgent, true, false);
// ^ V2.6: Throws exception because we try to save person.ReferringAgent with ID == 0
}
I am using 2.6 beta (May 15th 2008 ), adapter, .NET 3.5
Thanks,
Dan