Next Identity Key LINQ + SQL Server
- by user569347
To represent our course tree structure in our Linq Dataclasses we have 2 columns that could potentially be the same as the PK.
My problem is that if I want to Insert a new record and populate 2 other columns with the PK that was generated there is no way I can get the next identity and stop conflict with other administrators who might be doing the same insert at the same time.
Case: A Leaf node has right_id and left_id = itself (prereq_id)
**dbo.pre_req:**
prereq_id
left_id
right_id
op_id
course_id
is_head
is_coreq
is_enforced
parent_course_id
and I basically want to do this:
pre_req rec = new pre_req
{
left_id = prereq_id,
right_id = prereq_id,
op_id = 3,
course_id = query.course_id,
is_head = true,
is_coreq = false,
parent_course_id = curCourse.course_id
};
db.courses.InsertOnSubmit(rec);
try
{
db.SubmitChanges();
}
Any way to solve my dilemma? Thanks!