C# 是否将图像上载到mvc3中的数据库?

C# 是否将图像上载到mvc3中的数据库?,c#,asp.net-mvc-3,C#,Asp.net Mvc 3,我正在使用fileupload控件并上传图像,现在我想将该图像保存到我的数据库中,我们如何在mvc3中做到这一点 从网上得到了下面的代码,我们能用这段代码把图片上传到数据库吗,还有什么是ImageDB我不能理解的 [HttpPost] public ActionResult CreateImage(HttpPostedFileBase image) { Image newImage = new Image(); newImage.MimeT

我正在使用fileupload控件并上传图像,现在我想将该图像保存到我的数据库中,我们如何在mvc3中做到这一点

从网上得到了下面的代码,我们能用这段代码把图片上传到数据库吗,还有什么是ImageDB我不能理解的

    [HttpPost]
    public ActionResult CreateImage(HttpPostedFileBase image)
    {
        Image newImage = new Image();
        newImage.MimeType = image.ContentType;

        var binaryReader = new BinaryReader(image.InputStream);
        newImage.Data = binaryReader.ReadBytes(image.ContentLength);
        binaryReader.Close();

        imageDB.Images.AddObject(newImage);
        imageDB.SaveChanges();

        return RedirectToAction("Index");
    }

imageDB是实体框架中的数据库上下文。您当前如何与数据库交互?imageDB未声明/初始化!错误消息是什么?我使用的是企业库而不是实体框架,如何在这里使用企业库?我想我应该在模型中编写另一个方法,并在binaryReader.Close;行之后在这里调用该方法;?你看到错误了吗?运行上述代码时发生了什么?