Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
EF best practices for related tables
Message
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Entity Framework
Titre:
EF best practices for related tables
Versions des environnements
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01622184
Message ID:
01622184
Vues:
43
Hi everybody,

I am wondering if you can point me to the best practice approach in EF when we're talking about related tables.

Say, I see the following code for a similar situation which I am currently working with:
 public void AddTemplate(Template template, IEnumerable<Sites> assignedSites)
        {
            _templateRepository.Add(template);
            UpdateTemplateRemoteSites(template, assignedSites);
        }
        public void UpdateTemplate(Template template, IEnumerable<Sites> assignedSites)
        {
            _templateRepository.Update(template);

            UpdateTemplateRemoteSites(template, assignedSites);
        }
where the last method is:
  private void UpdateTemplateRemoteSites(Template template, IEnumerable<Sites> assignedSites)
        {
            IEnumerable<Sitelink> currentSiteLinks = _siteLinkRepository.GetSiteLinksForTemplate(template.TemplateId);
            IList<short> currentSites = currentSiteLinks.Select(x => x.SiteNo).ToList();
            IList<short> sites = assignedSites.Select(x => x.SiteNo).ToList();
            AssignRemoteSitesToTemplate(template, currentSites, sites);
            RemoveRemoteSitesFromTemplate(template, currentSites, sites);
        }
So, the template is associated with another table storing the sites. In the interface we're using the Mover for Assigned and Available Sites.

I am working on a similar scenario and I can just mimic that code but I am not 100% sure it's the best practice approach. As you can see, we save the information in the main table first (in the Adapter code) and then do the related table save. Based on that code I suspect that it happens in different SQL Server session.

So, my question is - is the listed approach OK or there is something that needs to be added to make it better?

Thanks in advance.
If it's not broken, fix it until it is.


My Blog
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform