We are using Linq2DB to read and write to an Oracle table, with an Oracle sequence to track the next value for the primary key.
I've worked out that I add a SequenceName attribute to the ID property, and Linq2DB calls MY_SEQ.NextVal:
public class myLinq2DBClass
{
[Column, SequenceName("MY_SEQ")]
public int Id { get; set; }
And then I create a new object like this:
var newObject = new myLinq2DBClass();
db.MyLinq2DBTable.Insert(newObject);
var newID = newObject.Id; // still zero?
Is there a way to get the new Id?
I had wondered if Insert would return it, but it returns the number of rows inserted.
linq2db
to don't track changes and do not retrieve values back without explicit operations. Use InsertWithInt32Identity
instead
var newID = db.InsertWithInt32Identity(newObject);