Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 233665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:07:17+00:00 2026-05-11T20:07:17+00:00

I’m new in asp.net mvc. I’m using Linq to Sql and trying to do

  • 0

I’m new in asp.net mvc.

I’m using Linq to Sql and trying to do everything loosely coupled.

I’ve two tables:

  1. News
  2. NewsFiles

What I’m trying to do is save a news and upload its files at the same time.

How can I create a news in conjunction with his files saving it to NewsFiles table?

The Linq to Sql model is Ok, it includes the object NewsFile to News object.

My concrete repository class for News table (noticia in portuguese):

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<noticia> ListNoticias()
        {
            return _entities.noticiaSet.ToList();
        }

        #endregion
    }
}

Look that’s not any mention to NewsFile object.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:07:17+00:00Added an answer on May 11, 2026 at 8:07 pm

    A strong word of advice: upload/attach the file(s) after the ‘attach target’ record has been created.

    I have a similar situation where i have (well almost the same actually) ‘Announcement’ object to which i can attach an image or a PDF attachment. My original idea was to allow the posting of the new Announcement (title, category, body, etc) with the file to upload. Now, admittedly i was trying to design for the upload of many files at the same time (and clever responses/validation for failed uploads).. but the point is: this approach was too hard. Do yourself a favour and have the user create the record first, then attach/upload the file(s) after. Having the primary key table record present will also make things easier.

    EDIT: More info about files and uploads:

    I use a File object to store files in my db (so yes i will need a binary/image field for the byte[]). Then i have other objects that represent concrete files, like Image and PdfDoc that inherit from File – these include other properties (like Width and Height for the Image type). I have a partial view that renders out a reusable upload control to the detail view which when submitted posts to the AttachImage() or AttachPdfDoc() methods for the particular Announcement (after it has been created – see above). The Service layer looks after storing the files, etc after validation and links the objects. Then the detail view reloads and the attached files are listed ready fo download by the public. (NB: This is heavily summarised btw – i also only allow the edit controls (upload form) on the detail view for authenticated users)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.