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.

Is possible to Reload object by PK?

See original GitHub issue

Hi Linq2Db!

Is it possible to do the reload of the object by PK? Something like this db.Reload(obj);

Indeed, methods db.Update(obj), db.Delete(obj), db.InsertOrReplace(obj) automatically generates SQL with filter by PK. I need this for SQL select (automatically filter by PK).

I cannot use “Find” method extension, because I need to reload object in common code and the type of object is unknown.

Could you provide me, what the best way for implementing this (workaround)? Thank you in advance!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sdanylivcommented, Aug 3, 2020

You can use FirstOrDefault. Yes ConfigurationID is hidden, if you have problem with finding better alternative I can look at. I think you’ve got an idea and can correct expression 😉 Usually I recommend this extension to analyze what is generated: ReadableExpressions

0reactions
AndrePScopecommented, Aug 1, 2020

Hi @sdanyliv ! Many-many thanks for your help and the solution!!!

Your code works well! I would ask some clarifying questions…

The first question. My linq2db version (3.0.1) does not know dc.MappingSchema.ConfigurationID.

image (I corrected this how I guess, but maybe you know how it will better…)

The second, when the select does not return the object, I got exception “Sequence contains no elements”. Probably this is Ok. Maybe the result of method Reload (true/false) also looks ok…

So, I can adapt this code. I just want to say many-many thanks! 😃 As for me, to have Reload in base functionality will be super!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reload django object from database - python
4 Answers. As of Django 1.8 refreshing objects is built in. Link to docs. This reloads all data from the database into the...
Read more >
Model instance reference
Refreshing objects from database¶ ... If you need to reload a model's values from the database, you can use the refresh_from_db() method. When...
Read more >
#901 (Reload method for models) – Django
Model.refresh() reloads all non-deferred local field values (that is, all fields in the current model which have a database column). In addition refresh()...
Read more >
3. How to reload a model object from the database?
Models can be reloaded from the databse using refresh_from_db() method. ... The object's updated value needs to be reloaded # from the database....
Read more >
EntityManager.save has inconsistent reload behavior in ...
So far as I can tell, the save option of { reload: boolean } is completely ignored when an entity is UPDATEd in...
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