Comments (7)
It should work if you remove the setter (e.g. set;
) in your POCO.
from dommel.
Hello, I'm experiencing same issue. I have a table with Id column, which is primary key and identity,
Id bigint IDENTITY(1, 1) NOT NULL
I have a class Token, works with table Token
public sealed class Token
{
public long Id { get; set; }
public string Token { get; set; }
}
when I trying to insert new record with method:
public void CreateToken(Token token)
{
using (var connection = CreateConnection())
{
connection.Insert(token);
}
}
I get an the above exception. The query, generated, by Dommel looks like this:
exec sp_executesql N'set nocount on insert into Token (Id, Token) values (@Id, @Token) select cast(scope_identity() as int)',
N'@Id bigint,@Token nvarchar(4000)',
@Id=0,@Token=N'8d539f27-71fd-49b2-897d-0837d85580bbd882a1e3-90f3-46bf-8005-a51e9af65b8f'
The problem is: generated query must not contain Id column and @id parameter. It should look like this:
exec sp_executesql N'set nocount on insert into Token (Token) values (@Token) select cast(scope_identity() as int)',
N'@Token nvarchar(4000)',
@Token=N'8d539f27-71fd-49b2-897d-0837d85580bbd882a1e3-90f3-46bf-8005-a51e9af65b8f'
How to achieve such behaviour? Is there a way to say Dommel that a column is an identity column?
from dommel.
@LiveLikeLastDay @enterpub this should be fixed in v1.7.3: https://www.nuget.org/packages/Dommel/1.7.3
FYI: you can use the [Key]
attribute to explicitly specify the key property for a type so it will be ignored when building queries.
from dommel.
Hi,
This change breaks the case when the Id actually comes from the application. This is breaking existing applications using Dommel.
from dommel.
I understand @ahoka. Although it was never the intention to set the primary key from the application side. However, I do think it might be a nice feature. I'm not sure yet how to implement both cases correctly without too much need for configuration. If someone of you have any suggestions, please share them.
from dommel.
@LiveLikeLastDay @enterpub @ahoka
I've update the IKeyPropertyResolver
interface so that it indicates whether a property is a an identity. This behavior can be configured. Dapper.FluentMap.Dommel will provide support for this soon.
See a7653b0.
from dommel.
Dapper.FluentMap.Dommel now supports configuring the identity of a property.
from dommel.
Related Issues (20)
- Combining predicate and One-to-many relations HOT 1
- SQLExpression does not use column mapping HOT 2
- Nuget 2.4.0 package issue HOT 2
- could you add a method to set the table name HOT 1
- missing selectAsync with joins HOT 1
- DateOnly and TimeOnly support HOT 2
- Not working with generic or abstract entity HOT 2
- SelectPaged and Multi Mapping HOT 1
- Issues resolving table names on derived types HOT 1
- Column Date in Postgres HOT 1
- Insert column with type of array HOT 1
- Automatic multi mapping N-hierarchy HOT 1
- One to Many Relation HOT 1
- Parentheses in SQL WHERE clause not working HOT 1
- Functions that may help HOT 1
- An error is occurring when executing Select - variable 'p' of type 'Escola.Entities.Aluno' referenced from scope '', but it is not defined HOT 1
- Multi-level foreign key relationships HOT 2
- Parentheses missing when combining multiple where statements
- DatabaseGeneratedOption.None not working HOT 2
- Dapper.FluentMap API error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dommel.