question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support insertion of keyless entities

See original GitHub issue

I’ve got a case where I’m writing time series data to a postgresql database. In mapping an Entity that represents a record in a time series table, I’ve explicitly and purposely forgone an ID field, because it’d likely overflow, and wont be used for anything in the future. (there are indexes there to help with querying, but they are specific to postgres/timescaledb).

I’ve marked the entity with [Keyless] and understand why the entity can’t be tracked, but I am confused by why entity framework couldn’t handle deletes and explicit inserts, and just fail to do an update where necessary. Can I turn off tracking for a specific DbSet or something, be able to take advantage of querying, inserts, and deletes?

Is there anyway to work around it and be able to write data with no id column to the the db, without having to manually write a bunch of parameterized insert statements?

Is there any likelihood of this being changed or improved in the future?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rojicommented, Jan 25, 2023

@ronnyek this is definitely something we intend to support.

Removing from the backlog as this is basically a dup of #29897.

0reactions
ronnyekcommented, Jan 25, 2023

Working on a completely separate project, totally different needs and I find myself needing this exact same thing again. Writing timeseries data that I can map and query as keyless, but cant insert. In my case I’m using npgsql and timescaledb, and timescale handles archiving/aggregation building etc. The closest thing to a key that I’d want would be the timestamp metric.

I get how keyless insert could be problematic with tracking and updates would be even more difficult, I don’t feel like I should have to revert to totally manual queries for writing… because efcore knows how to do this stuff already.

Inserts and tracking I get, but my specific use case I wont be fetching a record, and updating it. Infact I will be unlikely to ever update these keyless records.

So now I have to basically create/add an id column that I will never use taking up space…

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to insert primary keyless entity to table?
I'm working on with 15 years old DB.Now our scenario is DB first ,inserting an entity to primary keyless table.I read a lots...
Read more >
Keyless Entity Types - EF Core
Keyless entity types support many of the same mapping capabilities ... and therefore are never inserted, updated or deleted on the database.
Read more >
How to Define Keyless Entities in .NET EF Core
If you intended to use a keyless entity type, call 'HasNoKey' in 'OnModelCreating'. The error is asking to define a primary key on...
Read more >
Insert Records in Entity Framework Core
In this tutorial we will learn to Insert Records in Database with Entity Framework Core. EF Core can insert a single record or...
Read more >
EF Core Bulk Insert | Optimize Data Insertion for EF6 and ...
Optimize Entity Framework insert performance with EF Core Bulk Insert Extensions. Easily insert large numbers of entities and customize ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found