Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Where to store a function that involves two entities?

I have two tables in my database. Companies and Sites. Each Company has many Sites. The Sites table has has a foreign key of CompanyID.

I have a data layer class for each entity, one for the company, and one for the site.

I need to get the CompanyID by the SiteID and so I can write a method like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

public Guid GetCompanyGuidBySiteGuid(Guid siteId) =>
    _util.SelectGuid("SELECT s.CompanyID FROM pm.Site s WHERE s.SiteID = @SiteId", ("@SiteId", siteId));

Which data layer should I put this method in? The CompanyDataLayer, or the SiteDataLayer?

This is a specific question but also a general one. How does one make these kinds decisions in general when there are overlap between modules?

>Solution :

In this case, since you are trying to retrieve the CompanyID by the SiteID, it would be more appropriate to put the method in the SiteDataLayer class. This is because the method is related to retrieving information from the Site table based on the SiteID.

In general, when making decisions about where to put methods that involve multiple entities or tables, it is important to consider which entity or table the method is primarily related to. If the method is mainly focused on retrieving or manipulating data from one particular entity or table, then it should be placed in the corresponding data layer class.

However, if the method involves multiple entities or tables, it may be more appropriate to create a separate data layer class that is specifically designed to handle the interactions between those entities or tables. This class can then be used to encapsulate the functionality and make it easier to maintain and modify in the future.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading