Is possible to Reload object by PK?
See original GitHub issueHi 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:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
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.
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!