Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connection.Insert returning null - PK problem? #73

Closed
displaced opened this issue Jun 28, 2016 · 3 comments
Closed

connection.Insert returning null - PK problem? #73

displaced opened this issue Jun 28, 2016 · 3 comments
Assignees
Labels

Comments

@displaced
Copy link

Hi,

I've got a simple POCO ('Model.Client') which matches exactly my database fields. The mapper for that is defined as:

public class ClientMapper : CrudEntityMapper<Model.Client>
{
    public ClientMapper() : base("Clients")
    {
    }
}

...which I believe is the correct way to define a mapper if the model properties match the database fields.

Now, if I insert an instance of this model as so:

var ret = _conn.Insert(client);

...the row is added to the database table correctly, but ret is null. I believe this should either be the identity of the newly-inserted row, or an instance of the model that was inserted with the .Id property set appropriately.

My database correctly has an auto-incrementing primary key column named Id, and my entity object has a matching int Id { get; set; } property defined.

No exceptions appear to be thrown. I'm using the latest version of Griffin.Framework as available on NuGet.

It's almost as if the mapper hasn't picked up the presence of the Id field. Is there any way to see what's going on inside the mapper during use?

Any advice greatly appreciated!

@jgauffin
Copy link
Owner

can you post the SQL for your table?

@jgauffin
Copy link
Owner

sqlite or sql server?

@jgauffin
Copy link
Owner

Not all tables use auto incremented primary keys and therefore it's not turned on per default.

To allow Griffin.Framework to pick up the generated value you need to configure it:

public class ClientMapper : CrudEntityMapper<Model.Client>
{
    public ClientMapper() : base("Clients")
    {
        Property(x => x.Id)
            .PrimaryKey(true); //true = autoinremented
    }
}

reopen if that's not your issue.

@jgauffin jgauffin self-assigned this Sep 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants