我是asp.net mvc的新手.
我正在使用Linq到Sql并试图做松散耦合的一切.
我有两张桌子:
我要做的是保存新闻并同时上传文件.
如何与他的文件一起创建新闻,将其保存到NewsFiles表?
Linq to Sql模型没问题,它包含对象NewsFile到News对象.
我的新闻表的具体存储库类(葡萄牙语中的noticia):
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 …Run Code Online (Sandbox Code Playgroud)