Comments (6)
From @pantonis on March 4, 2016 18:59
Hi,
entity.Property(e => e.IDFactura) .HasDefaultValueSql("nextval('\"Factura_FacturaID_seq\"'::regclass)") .ValueGeneratedNever();
should be:
entity.Property(e => e.IDFactura) .HasDefaultValueSql("nextval('\"Factura_FacturaID_seq\"'::regclass)") .ValueGeneratedOnAdd();
Had the same problem. Think when the reverse engineer tool creates the context it creates ValueGeneratedNever(); instead of ValueGeneratedOnAdd();.
This is a pain because every time I update my context I have to go and update everything manually.
from efcore.pg.
From @angelcalvasp on March 17, 2016 20:17
thanks for the workaaround,maybe this should be fixed?, a bug maybe?
from efcore.pg.
@angelcalvasp, @pantonis, the Npgsql EFCore provider has logic to identify serial columns and reverse-engineer them properly. It seems this logic doesn't pick up your column because of naming issues: your database column appear to be called IDFactura, while the sequence associated to the column is called Factura_FacturaID_seq (note the ID coming after Factura). This probably means you manually named your column or sequence.
In any case, this is a bug - the provider should be able to handle this. Can you please just confirm how exactly you create your schema?
from efcore.pg.
Waiting on dotnet/efcore#5366
from efcore.pg.
In your calling of nextval()
, it looks like you're passing in parameters. Is that the case? I'm attempting to use HasDefaultValueSql()
to set a property on my model when on INSERT, but I would need to pass a parameter to my function.
from efcore.pg.
@im1dermike, whatever you pass as the argument to HasDefaultValueSql()
will be set on your PostgreSQL column definition, as-is - you can put any valid PostgreSQL expression. However, that expression can't be parameterized - it's set just once when creating the column (parameterizing it would make no real sense). The placeholders you see in the expression nextval('{tableName}_{columnName}_seq'::regclass)
are simple C# parameters to set the table and column names.
If you need more info, try to explain your scenario and why you think you need parameterization.
from efcore.pg.
Related Issues (20)
- Translate primitive collections with composed LINQ operators via PG array constructor
- [Bug] Connection already open on Database.Migrate() HOT 2
- Migrations references actual enum types which break them HOT 4
- Npgsql.PostgresException:42601 : at or near "schemaname": syntax error. Detail redacted as it may contain sensitive data (Error getting while calling Stored procedure from .Net core 8.0 used Npgsql.EntityframeworkCore.PostgreSQL. HOT 2
- Updgrade from v6 -> v8. TimeZoneInfo.ConvertTimeBySystemTimeZoneId: No coercion operator is defined between types 'NodaTime.LocalDateTime' and 'System.Nullable`1[System.DateTime]' HOT 1
- InvalidCastException with Instant field (using NodaTime) when many database connections are open HOT 2
- Backward compatibility of SQL translation for DateTime.Date HOT 2
- Migration to .NET 8: Period Mapping and IServiceProvider Limit Issue HOT 4
- Migrations applied with one role and queries with another HOT 9
- Npgsql.PostgresException: '42883: function st_distance(point, geometry) does not exist HOT 4
- Cache issue HOT 3
- Error retrieving data when combining TPH and complex types
- Unable to Fetch Data from Stored Procedure with Cursor as return type and getting required column id was not present in the results of a "FromSql" operation.
- Implement migration locking
- Replace type reloading mechanism with the new EF migration extensibility mechanism
- DateOnly - en_GB date flipped from October to April. HOT 2
- LTree column type doens worked with migration
- Errors on mapping enum types to SQL and storing into database
- Is there way to translate EF Core query to WITH Queries (Common Table Expressions) ? HOT 3
- Select or filter Length of string contained in JsonB column
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 efcore.pg.