Entity Framework 4.0 如何更新对象
我要在方法里传入一个对象,用这个对象去更新数据库里的对角。
代码如下:
public int UpdateNewsDoc(NewsDoc nd, EntityCollection<NewDocAttachments> Attachments, EntityCollection<InNewsPicSwf> InNewsPicSwfs)
{
try
{
using (var db = new JiXiaoWebSite_DAXLJWEntities())
{
if (Attachments != null && Attachments.Count > 0)
{
IList<NewDocAttachments> DelAttachmentsList = Attachments.Where(a => a.IsDel == true).ToList();
while (DelAttachmentsList.Count > 0)
{
if (FileHelper.IsExistFile(HttpContext.Current.Server.MapPath(DelAttachmentsList.ElementAt(0).AttachmentsURL.Trim() + DelAttachmentsList.ElementAt(0).AttachmentsName.Trim())))
{
FileHelper.DeleteFile(HttpContext.Current.Server.MapPath(DelAttachmentsList.ElementAt(0).AttachmentsURL.Trim() + DelAttachmentsList.ElementAt(0).AttachmentsName.Trim()));
}
Attachments.Remove(DelAttachmentsList.ElementAt(0));
DelAttachmentsList.Remove(DelAttachmentsList.ElementAt(0));
}
}
if (InNewsPicSwfs != null && InNewsPicSwfs.Count > 0)
{
IList<InNewsPicSwf> DeInNewsPicList = InNewsPicSwfs.Where(a => a.IsDel == true).ToList();