0

I'm engaged in a minor skirmish with Dynamic Data. I've got a custom database image field template to allow users to upload and edit images where inserting works but updating does not. I can make update work by removing the if insert mode around where the uri is set in the following code (in DBImage_Edit.ascx.cs):

protected override void ExtractValues(IOrderedDictionary dictionary)
{
  ...
  dictionary["contenttype"] = "image/" + imgext;
  dictionary["filecontents"] = new System.Data.Linq.Binary(FileUploadEdit.FileBytes);
  if (Mode == DataBoundControlMode.Insert)
  {
    dictionary["uri"] = imgname + "_" + DateTimeOffset.Now.Ticks.ToString() + "." + imgext;
  }
  ...
}

To recap, if the uri is set to something different than the previous value in the DB when editing, the new image is uploaded successfully. If the uri is the same as the previous value in the DB, even though the filecontents and contenttype are changed, SQL Server never gets the news.

The metadata:

...
[DisplayName("Uri")]
[ScaffoldColumn(true)]
[Required]
public object uri { get; set; }

[DisplayName("Graphic")]
[ScaffoldColumn(true)]
[UIHint("DBImage")]
public object filecontents { get; set; }
...

I've also removed the UpdateCheck but that did not seem to change the behavior:

[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_filecontents", DbType="VarBinary(MAX)")] //, UpdateCheck=UpdateCheck.Never
public System.Data.Linq.Binary filecontents
  {
    get
    {
...

(See commented out UpdateCheck=UpdateCheck.Never above)

Kind regards,

Jordan

4

1 回答 1

0

我把它放了一个星期,回来后很容易就明白了。有时你只需要出去走走,不要想太多这些事情。

问题是缓存。我通过在 OnDataBinding 中添加 nocache 参数来更改图像处理程序 url:

老的:

ImageEdit.ImageUrl = "http://localhost/WebServices.CAD/ImageHandler.ashx?uri=" + row.uri;

新的:

ImageEdit.ImageUrl = "http://localhost/WebServices.CAD/ImageHandler.ashx?nocache=" + System.DateTime.Now.Ticks.ToString() + "&uri=" + row.uri;

按设计工作。

于 2013-03-25T18:46:01.727 回答