Return new row identity

3 posts, 0 answers
  1. Richard M
    Richard M avatar
    76 posts
    Member since:
    Mar 2010

    Posted 24 Nov 2010 Link to this post

    I am trying to find an example for returning the ID of a newly created row using the EntityDiagrams model, instead of the ObjectScope method.  The "InsertOnSubmit" and "SubmitChanges()" properties are not available in the EntityDiagrams model.
  2. Richard M
    Richard M avatar
    76 posts
    Member since:
    Mar 2010

    Posted 24 Nov 2010 Link to this post

    Ok, I figured out how to do this:

    (Here's my table)
    New table "TestTable"
    UID (PK, int),
    FieldName (varchar(20))


    // Create a new connection:
    MyEntityDiagrams conn = new MyEntityDiagrams();

    //Create a new instance of the table:
    TestTable myTable = new TestTable();

    // Add field values:
    myTable.FieldName = "fieldname";

    // Add the new record to TestTable:
    conn.Add(myTable);
    conn.SaveChanges();

    //  Retrieve the ID for the row that was created
    int ID = myTable.UID;
  3. DevCraft banner
  4. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 25 Nov 2010 Link to this post

    Hello Richard M,

    Yes, this is the correct way to get the newly generated id value. Please let us know if you need further assistance.

    All the best,
    Alexander
    the Telerik team
    Accelerate your learning with industry's first Telerik OpenAccess ORM SDK. Download today.
Back to Top