Note that there are some explanatory texts on larger screens.

plurals
  1. POasp.net mvc 1 to many saving post and upload files
    text
    copied!<p>I'm new in asp.net mvc.</p> <p>I'm using Linq to Sql and trying to do everything loosely coupled.</p> <p>I've two tables:</p> <ol> <li>News</li> <li>NewsFiles</li> </ol> <p>What I'm trying to do is save a news and upload its files at the same time.</p> <p>How can I create a news in conjunction with his files saving it to NewsFiles table?</p> <p>The Linq to Sql model is Ok, it includes the object NewsFile to News object.</p> <p>My concrete repository class for News table (noticia in portuguese):</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace MagixCMS.Models { public class NoticiaRepository : INoticiaRepository { #region INoticiaRepository Members magixcmsEntities _entities = new magixcmsEntities(); public noticia CreateNoticia(noticia noticiaToCreate) { _entities.AddTonoticiaSet(noticiaToCreate); _entities.SaveChanges(); return noticiaToCreate; } public void DeletaNoticia(noticia noticiaToDelete) { var noticiaOriginal = GetNoticia(noticiaToDelete.Id); _entities.DeleteObject(noticiaOriginal); _entities.SaveChanges(); } public noticia EditNoticia(noticia noticiaToEdit) { var noticiaOriginal = GetNoticia(noticiaToEdit.Id); _entities.ApplyPropertyChanges(noticiaToEdit.EntityKey.EntitySetName, noticiaToEdit); _entities.SaveChanges(); return noticiaToEdit; } public noticia GetNoticia(int id) { return (from c in _entities.noticiaSet where c.Id == id select c).FirstOrDefault(); } public IEnumerable&lt;noticia&gt; ListNoticias() { return _entities.noticiaSet.ToList(); } #endregion } } </code></pre> <p>Look that's not any mention to NewsFile object.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload