After Insert No Return ID value #213

Closed
comfreakph opened this Issue Jul 13, 2014 · 7 comments

Projects

None yet

4 participants

@comfreakph

After successfully insert there's no return value for ID

Sample Code:

public dynamic SaveUser(string name, string email)
{
    dynamic result = new ExpandoObject();
    result.Success = false;
    try
    {
        result.User = this.Insert(new { 
            Name = name, 
            Email = email
        });
        result.Success = true;
        result.Message = "Successfully saved!";
    }
    catch (Exception ex)
    {
        result.Message = ex.Message;
    }
    return result;
}

if you look at the SaveUser.User.ID, the value is Null

this was working in the previous versions.

Thanks

@robconery
Collaborator

What database are you using?

@comfreakph

Ms sql
On Jul 14, 2014 2:36 AM, "Rob Conery" notifications@github.com wrote:

What database are you using?


Reply to this email directly or view it on GitHub
#213 (comment).

@earljon
earljon commented Jul 18, 2014

I'm having the same issue using MS SQL provider. But when I revert back the changes made on this commit: ac72ee8 , from using SCOPE_IDENTITY() to @@IDENTITY, the ID now is showing a value generated by the SQL Server.

@FransBouma
Owner

(I took over Massive from Rob, so that's the reason why this reply is so late ;))

Do you happen to have a trigger on the table which is executed on insert which does inserts with identity fields too? In the case of a trigger being present, @@IDENTITY is required, as SCOPE_IDENTITY() then won't cut it.

@robconery
Collaborator

SCOPE_IDENTITY vs. @@IDENTITY is my biggest issue - SQL Server people want SI, CE and lighter versions of SQL don’t support it.

On March 4, 2015 at 5:30:04 PM, Frans Bouma (notifications@github.com) wrote:

(I took over Massive from Rob, so that's the reason why this reply is so late ;))

Do you happen to have a trigger on the table which is executed on insert which does inserts with identity fields too? In the case of a trigger being present, @@IDENTITY is required, as SCOPE_IDENTITY() then won't cut it.


Reply to this email directly or view it on GitHub.

@FransBouma
Owner

Good point. CE is phased out though by Microsoft, however people will have to use it still. It might be good to have a compatibility setting, which could also guide paging code for e.g. sql server 2014, newsequentialid() creation etc. and make distinction between trainwreck databases (CE) and normal DBs (normal sqlserver)

@FransBouma
Owner

This is fixed in the Refactoring branch in the next commit, for SQL Server.

@FransBouma FransBouma closed this Jul 3, 2015
@FransBouma FransBouma added a commit that referenced this issue Jul 3, 2015
@FransBouma Fixed issue #213
Added tests for Writes/Deletes.
Fixed issues related to Update/Insert which were introduced after
refactoring
Added DynamicModel.SaveAsNew()
Fixed readme, as it contained an error in the insert example.
9fa2dcc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment