Giter Site home page Giter Site logo

Comments (6)

roji avatar roji commented on August 16, 2024

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.

roji avatar roji commented on August 16, 2024

From @angelcalvasp on March 17, 2016 20:17

thanks for the workaaround,maybe this should be fixed?, a bug maybe?

from efcore.pg.

roji avatar roji commented on August 16, 2024

@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.

roji avatar roji commented on August 16, 2024

Waiting on dotnet/efcore#5366

from efcore.pg.

im1dermike avatar im1dermike commented on August 16, 2024

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.

roji avatar roji commented on August 16, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.