Well I have enjoyed tremendously using CSLA for building the many applications I have worked on and now I am building a whole new app using CSLA 3.5.1, VS08 and CodeSmith. But I can't for the life of me figure out why this does not work.
I have an IMAGE field in SQL and am simply trying to pull it from my Fetch method using this but it does not seem to work. I get all sorts of syntax errors, anyone have any insight into pulling an image from SQL using 3.5.1?
LoadProperty<
byte[], byte[]?>(ImageProperty, data.Image);Have not had time to try the new stuff.
But I pull out images from SQL Server all the time.
I use code like this to define the Property and field:
Protected mImage As Byte() = Nothing
Public Overridable Property Image() As Byte()mImage =
CType(dr.Item("image"), Byte())Joe
Try this:
LoadProperty<byte[], byte?[]>(ImageProperty, data.Image);
ie: move the question mark to before the square brackets.
Regards,
Patrick
I did try that. I think the key here is I am using LINQ as well and so the specific error I am getting is cannot convert from 'System.Data.Linq.Binary' to 'byte?. Any more ideas on how to make this work?
**************** Problem Resolved ******************
I resolved the problem. Frank Wang has a good explanation of how to tell LINQ to use System.Byte[] due to serialization issues. http://geekswithblogs.net/frankw/Default.aspx after following his step then I simply changed the LoadProperty line to:
LoadProperty<byte[]>(StudentImageProperty, data.StudentImage);
It works for now.
Here how I do it (I amusing a stored procedure here to return data). Here the Image field is a Byte array.
Private Overloads Sub DataPortal_Fetch(ByVal criteria As SingleCriteria(Of BLPhotoAlbum, System.Int32))
Using ctx = ContextManager(Of ProjectTrackerDataContext).GetManager("ProjectTracker")
Dim data = ctx.DataContext.spSelectPhotoAlbum(criteria.Value).Single()
LoadProperty(Of System.Int32)(_ImageId, data.ImageId)
LoadProperty(Of System.String)(_Description, data.Description)
If data.Image IsNot Nothing Then
_Image = data.Image.ToArray()
End If
End Using
End Sub
Copyright (c) Marimer LLC