|
| Having issues with LINQ for Master/Detail record inserts - need help on inserting master then detail records please |
 |
Thu, 3 Apr 2008 13:32:44 +0000 |
This is driving me up the wall :)
I have a master/detail setup that I need to get LINQ to handle and I'm using
VB.
I have supervisors who perform audits on their staff. A supervisor will create
a new audit record (they audit them once a quarter) and that audit record will
then contain the many audit details (each with a score).
The audit details and their scores are being scored against audit criteria.
There is a table of audit criteria and when an audit master record is created I
need to get all the active audit criteria and then create an AuditDetail record
under the master audit record for each audit criteria.
i.e.:
New Audit Record:
AuditID (PK)
(staff names, dates, etc...)
Now there are 5 active AuditCriteria records so I now need to make 5 AuditDetail
records:
AuditDetailID (PK)
AuditID (FK back to the parent audit record)
AuditCriteriaID (FK to the single audit criteria that this audit detail record
is holding a score for)
I think part of my issues are that most of the documentation seems to be from
the beta preview of LINQ (ScottGu's blog is an excellent source I have been
using), BUT some of the keywords seem to have changed .InsertOnSubmit instead of
.Add, etc..
Anyway, could someone please help me get this sorted out?
My code was basically that I'd set a datacontext of course then I'd get the
auditcriteria:
Dim myAuditCriteria = From ac IN db.AuditCriterias _
Where ac.Active = True _
Select ac
At that point I created a new audit master record
Dim Audit as New CaseAudit
'--I set some values like the auditor ID, dates, etc...
db.CaseAudits.InsertOnSumbit(Audit)
'--- now I move onto my FOR EACH NEXT loop which I think I'm doing wrong:
For Each criteria in myAuditCriteria
Dim AuditDetail As New AuditDetails
AuditDetail.AuditCriteriaID = criteria.AuditCriteriaID
'--some more random fields
Audit.AuditDetails.Add(AuditDetail)
NEXT
db.SubmitChanges()
Then at that point I get an error that my datetimes are out of range:
SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999
11:59:59 PM.
however, I tested with just a SINGLE record being added and the same datetime
values and it worked just fine, so I think it is something else. I also set the
default values on SQL Server to GetDATE() for the datetime fields and then did
NOT send any datetime data with LINQ and I STILL got the error. So it must be a
glitch and that isn't the actual error.
Any help would be GREATLY appreciated!
|
| Post Reply
|
|
|
|
|
|
|
|
|
|