Handling auto-incrementing IDENTITY SQL Server fields with LINQ to SQL in C?

The identity will only be generated when you call SubmitChanges, so your approach listed is a viable option What you can do however is to set the FK object rather than ID on the other object and LINQ to SQL will work it out for you EG: If TableA. TableBID is an FK to TableB. TableBID then you're referring to taking: TableB be = new TableB(); context.TableB.

InsertOnSubmit(b); context.SubmitChanges(); TableA a = new TableA(); a. TableBID = b. TableBID; context.TableA.

InsertOnSubmit(a); context.SubmitChanges() But you can do it in a single submit by setting the object for the FK like this: TableB be = new TableB(); context.TableB. InsertOnSubmit(b); TableA a = new TableA(); a. TableB = b; context.TableA.

InsertOnSubmit(a); context.SubmitChanges() Which isn't much shorter code-wise in this example, but it does allow only 1 spot where you commit which is typically a good thing structurally.

The identity will only be generated when you call SubmitChanges, so your approach listed is a viable option. What you can do however is to set the FK object rather than ID on the other object and LINQ to SQL will work it out for you. EG: If TableA.

TableBID is an FK to TableB. TableBID then you're referring to taking: TableB be = new TableB(); context.TableB. InsertOnSubmit(b); context.SubmitChanges(); TableA a = new TableA(); a.

TableBID = b. TableBID; context.TableA. InsertOnSubmit(a); context.SubmitChanges(); But you can do it in a single submit by setting the object for the FK like this: TableB be = new TableB(); context.TableB.

InsertOnSubmit(b); TableA a = new TableA(); a. TableB = b; context.TableA. InsertOnSubmit(a); context.SubmitChanges(); Which isn't much shorter code-wise in this example, but it does allow only 1 spot where you commit which is typically a good thing structurally.

Great, thanks! About to implement. – Maxim Zaslavsky Jun 17 '10 at 4:19.

The identity will only be generated when you call SubmitChanges, so your approach listed is a viable option. What you can do however is to set the FK object rather than ID on the other object and LINQ to SQL will work it out for you. EG: If TableA.

TableBID is an FK to TableB. Which isn't much shorter code-wise in this example, but it does allow only 1 spot where you commit which is typically a good thing structurally.

The identity will only be generated when you call SubmitChanges, so your approach listed is a viable option.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions