Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
EF best practices for related tables
Message
 
 
To
All
General information
Forum:
ASP.NET
Category:
Entity Framework
Title:
EF best practices for related tables
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01622184
Message ID:
01622184
Views:
45
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
Next
Reply
Map
View

Click here to load this message in the networking platform