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

Insert with default values #4

Open
imalliar opened this issue Feb 26, 2015 · 1 comment
Open

Insert with default values #4

imalliar opened this issue Feb 26, 2015 · 1 comment
Assignees
Labels

Comments

@imalliar
Copy link

When the table has only identity and computed columns the correct format of the insert statement is:
INSERT INTO table_name DEFAULT VALUES.
Instead, the code generated by SqlGenerator is:
INSERT INTO table_name which is incorrect.
Is there any workaround?
Thanks in advance

@Yoinbol
Copy link
Collaborator

Yoinbol commented Feb 26, 2015

Hi, yes. You can override the Insert function on the given repository and inject there your statement (but only if you are using this package in conjunction with Dapper.DataRepositories).
Lets say your table is called "Persons" so I'm guessing you have a "PersonsRepository". What you can do is:

public override bool Insert(Person instance) {
return this.Connection.Execute("INSERT INTO Persons DEFAULT VALUES", new {}) > 0;
}

Now, if you are not using Dapper.DataRepositories what we can do is create an attribute called "DefaultValues" or something like that to decorate your class and append the "DEFAULT VALUES" statement to the end of the generated statement.

@Yoinbol Yoinbol self-assigned this Feb 26, 2015
@Yoinbol Yoinbol added the bug label Feb 26, 2015
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