views:

85

answers:

1

LINQ to SQL by default maps a binary column (varbinary, image, ...) to a property of the type 'System.Data.Linq.Binary'. Working with binary data this way is not that hard, but you can manually change that mapping to 'byte[]', making it easier to work with binary data (since you don't have to convert it in code anymore.

What's the disadvantage of doing this? Why is was the Binary type chosen as the default for these types of columns. Why does the Binary type even exist at all? My guess is that using the Binary type for some reason allows you to "lazy load" the binary data, but that's just my guess and I can't find any documentation that proves this.

Does anyone else have more information concerning this?

UPDATE:

According to this blogpost, the way to make a Binary property lazy loading is by setting the "delay loaded" property to True, which turns the property datatype into Link. That would indicate that a regular Binary property doesn't do lazy loading by itself. So my question remains: what benefit does a Binary have over byte[]?

+1  A: 

I found this mention here:

The Binary type exists because LINQ to SQL cannot track changes made to a byte[]. It only tracks changes made to a property when you assign a new byte[] to it. The Binary type is an immutable version of byte[], like the String type is an immutable version of char[]. Since you cannot change the contents of a Binary type, the only way to modify it is to assign your property a new instance.

Dave Van den Eynde