At first glance, I don’t see your current way of working being “inefficient” (with the information provided). I would replace the code:
SELECT * FROM dbObject p LEFT JOIN dbTagConnection c on p.Id= c.PointId LEFT JOIN dbTags t on c.TagId = t.dbTagId WHERE ...
by two calls to the DALs methods, first to get the main data of the object (1) and one of them, to get only the data associated with the tags (2) so that your factory can fill out the List of object tags:
(1)
SELECT * FROM dbObject WHERE Id=@objectId
(2)
SELECT t.* FROM dbTags t INNER JOIN dbTag Connection c ON c.TagId = t.dbTagId INNER JOIN dbObject p ON p.Id = c.PointId WHERE p.Id=@objectId
If you have many objects, and the amount of data is only a few (this means that you are not going to manage large volumes), I would look for an ORM solution as Entity Framework .
I (still) feel comfortable writing SQL queries to the DAO to control all queries sent to the database server, but, in the end, this is due to the fact that in our situation there is a need. I do not see any inconvenience associated with the need to query the database to restore, firstly, the object data ( SELECT * FROM dbObject WHERE ID=@myId ) and populating the object instance, and then again request the database to restore all satellite data that may you will need (tags in your case).
Please tell us more about your scenario so that we can provide valuable guidance for your specific scenario. I hope this is all the same to you.
source share