techiehippy wrote:
The error is occurring when trying to update the data in the logindetails table (like changing a password).
I made the assumption that having an instance of the employee entity and then making changes to the data in the related logindetails entity would in effect cause an update and not try to insert a new record.
Back to square one. I now indeed see you try to update 2 existing entities, not create 2 new ones. My mistake, my example did that.
Your line here:
Dim logindetails As LoginDetailsEntity = employee.LoginDetails
will fetch the LoginDetails for the entity with the passed in PK for employee. You stated that loginDetails is new. This means that there isn't a LoginDetails object in the database for the employee with pk _userK. Which is a bit odd, as when you add a new one, it fails due to a unique constraint error...
When you fetch logindetails using the unique constraint (FetchUsingUCEmployeeK or something) and pass in _userK, does it fetch an entity or not?
1:1 relations did have some problems in the past, where the code generator made mistakes what to do when a related entity was referenced: call by unique constraint or call by PK. In your case, the EmployeeEntity.GetSingleLogindetails method should have a _loginDetails.FetchUsingUC... call, not a PK call. Could you check that for me, please?
This O/R stuff is really great but I am still trying to get my head around some of the concepts (simple as they may be!). Do you know of any good articles that could help explain this to me in greater detail? Frans, when did you first discover this model and how did you learn about it?
LLBLGen Pro uses O/R mapping, though doesn't implement all facets of O/R mapping (yet), inheritance isn't implemented yet (will be in april).
The 'standard' work on this is this essay:
http://www.agiledata.org/essays/mappingObjects.html
and I also learned a lot from the O/R mapper called SimpleORM: http://www.simpleorm.org/ as it comes with a good explanation of what it does (technically). Though a lot is redesigned by me, as I wanted a more practical paradigm build in, thus not 'pure O/R mapping' but more a practical implementation of o/r mapping, so users don't have to learn deep details about o/r mapping before understanding that using an entity in code is like using a table in sql.