-
-
Notifications
You must be signed in to change notification settings - Fork 496
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
Prevent database generated columns from being inserted. #339
Comments
I was looking for a solution like this as well. +1 |
Not sure whether this can help you, but you can use Dapper.Contrib, which has an Insert method and you can use attributes ([Key], [Computed]...) that will prevent properties from being added to the insert query (it also works for update queries). I've realized that the query builder lacks some of the features I need, but with the QueryFactory you can get the IDbConnection and then use any of the Dapper methods. |
@abravodev Yes Dapper.Contrib has a Key attribute to decorate your POCOs properties as a column whose value is generated by the database, however I noticed that SqlKata too has a [Key] attribute. I thought it would work the same as Dapper's but it didn't. Do you know what is SqlKata [Key] attribute for? |
@grounzero and @abravodev, I decorated my POCO with the [Ignore] SqlKata key attribute and it worked for insertions, SqlKata no longer includes the decorated column in the INSERT statement, but it includes it in SELECT statements, so it works for me. |
The The select query is not affected at all. |
[IgnoreAttribute] is great at preventing database generated columns from being added to the insert list but it prevents the column from populated during a Get and irt appears
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
is not recognised.How can I work around this?
The text was updated successfully, but these errors were encountered: