Next Identity Key LINQ + SQL Server

Posted by user569347 on Stack Overflow See other posts from Stack Overflow or by user569347
Published on 2011-01-10T04:23:55Z Indexed on 2011/01/10 5:53 UTC
Read the original article Hit count: 154

Filed under:
|
|

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!

© Stack Overflow or respective owner

Related posts about c#

Related posts about sql-server