How to Get Identity after InsertOnSubmit

Linq puts the identity (Id) of the inserted record into the inserted instance object during the Submit operation. After calling Submit get the Id. 

Example:

        public void HandleInsert(string Handle, int CompanyId, ref long HandleId)
        {
            DataClasses1DataContext DbObj;
            PhraseHandle HandleObj;

            using (DbObj = new DataClasses1DataContext())
            {
                HandleObj = new PhraseHandle();
                HandleObj.PhraseHandle1 = Handle;
                HandleObj.CompanyId = CompanyId;
                DbObj.PhraseHandles.InsertOnSubmit(HandleObj);
                DbObj.SubmitChanges();
                HandleId = HandleObj.PhraseHandleId;
            }
        }




Site Map | Printable View | © 2008 - 2012 Sandy Pond Consulting | Powered by mojoPortal | HTML 5 | CSS | Design by styleshout