简体   繁体   中英

SharePoint 2010: Error Mapping to Picture Hyperlink with SPMetal

Whenever I have a column of type hyperlink with the format set for pictures, I get an error whenever there is actually a value in that column. The exception it throws is "Specified cast is not valid".

My thought is that the problem is either here (the FieldType being set to Url):

[Microsoft.SharePoint.Linq.ColumnAttribute(Name = "FOO", Storage = "FOO_", FieldType = "Url")]
public string FOO
{
    get
    {
        return this._FOO;
    }
    set
    {
        if ((value != this._FOO))
        {
            this.OnPropertyChanging("FOO", this._FOO);
            this._FOO = value;
            this.OnPropertyChanged("FOO");
        }
    }
}

Or here (it being cast to a string):

private string _FOO;

But I'd have no idea what the proper values for either of those fields should be. Any help would be greatly appreciated.

It works whenever this field does not have data in it and I JUST used SPMetal to generate the class, so I'll get the two most obvious questions out of the way.

Link to the answer: https://mgreasly.wordpress.com/2012/06/25/spmetal-and-workflow-associations/

Turns out it is a known bug when mapping lists that have associated workflows. SPMetal assigns it as a nullable integer when it's supposed to be an Object, hence the cast error.

Workaround: manually edit the mappings to make the type it returns an object or ignore the column by using a parameter map.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM