I'm getting a little bit confused on how to save an object to an SQL server database with Linq. Does anyo开发者_开发问答ne has an example for this?
I have an varbinary(max) field in the sql server and in Linq it is associated as System.Data.Linq.Binary.
How to convert my object from and to the Linq binary property?
For converting a binary data element to a byte array for returning to a browser check out this blog http://weblogs.asp.net/bryansampica/archive/2007/11/29/converting-sql-linq-binary-to-byte.aspx which suggest using queryresult.First.ToArray()
For saving binary data from a memory stream check out the comment in this blog http://social.msdn.microsoft.com/Forums/en-US/adodotnetentityframework/thread/e8acefbc-8dc5-4ad0-82c3-b559b343ec2a/ which suggests using the GetBuffer() method on the memory stream to acquire the binary data before submitting to the database.
That's not what LINQ does.
LINQ to SQL allows you to create special data objects that correspond to existing tables in SQL Server.
精彩评论