Entity Framework 4 getting primary key ID for inserted record

后端 未结 3 1205
后悔当初
后悔当初 2020-12-15 03:11

I am using the Entity Framework for inserting a row into my sql database. If I was to be using a stored procedure then I would be able to return the primary key for the reco

3条回答
  •  一整个雨季
    2020-12-15 03:46

    For Oracle.ManagedDataAccess.EntityFramework (version 6.121 or older)

    If you still do not get the ID after inserting, then add this attribute on the primary key property.

    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
     public string ID { get; set; }
    

    I had to do this, don't know why, may be because I am using oracle and entity framework is not happy about that.

    Edit: I see this answer is down voted, and I know why, because the latest version of ODAP doesn't require you to put the [DatabaseGenerated(DatabaseGeneratedOption.Identity)]. But this was true for the older versions.

提交回复
热议问题