none
sql datatype 'image' to a c# type? RRS feed

  • Question

  • hey,

    When updating a datatype image it checks if it is changed zo then it will update or not. But it seems to crash when i tries to compare:

    "The data types image and varbinary are incompatible in the equal to operator."

    i declared the type as:

            private byte[] _memoIntern;
            [Column(Name="MEMO_INTERN_RTF")]
            public byte[] MemoIntern
            {
                get { return this._memoIntern; }
                set { this._memoIntern = value; }
            }

    What am i missing here?

    TIA

    Wednesday, April 7, 2010 12:35 PM

Answers

  • Your property is of type byte[] and has DbType not set in the column attribute, so Linq will assume it's varbinary. While byte[] should work, the default for image type is System.Data.Linq.Binary
    Update check should be never for ntext, text and image since SQL Server doesn't support comparison for these types.
    If you want update check functionality then just change the database type for the field to varbinary(max)

    [Column(Storage="_memoIntern", Name="MEMO_INTERN_RTF", DbType="IMAGE", CanBeNull=false, UpdateCheck=UpdateCheck.Never)]
    public System.Data.Linq.Binary MemoIntern
    
    • Marked as answer by ...NoiK Monday, April 12, 2010 7:13 AM
    Sunday, April 11, 2010 10:35 PM

All replies

  • Are you trying to store the Image in the setter property or a byte array of the image?

    Also, what is the datatype for the column in the Database?

    Sunday, April 11, 2010 10:08 PM
  • Your property is of type byte[] and has DbType not set in the column attribute, so Linq will assume it's varbinary. While byte[] should work, the default for image type is System.Data.Linq.Binary
    Update check should be never for ntext, text and image since SQL Server doesn't support comparison for these types.
    If you want update check functionality then just change the database type for the field to varbinary(max)

    [Column(Storage="_memoIntern", Name="MEMO_INTERN_RTF", DbType="IMAGE", CanBeNull=false, UpdateCheck=UpdateCheck.Never)]
    public System.Data.Linq.Binary MemoIntern
    
    • Marked as answer by ...NoiK Monday, April 12, 2010 7:13 AM
    Sunday, April 11, 2010 10:35 PM
  • Thank you, it seems your solution has work.

    Can you tell me if the "get" property will be used by linq? Or does assigning the storage attribute to it will pass that function and go straight into the _ memoIntern type?

    TIA

    Monday, April 12, 2010 7:15 AM
  • It will be used.
    Monday, April 12, 2010 7:33 AM