1

i have a stored procedure which returns single column of datatype image.stored procedure is added to linq to sql class.how can i create byte array from the stored procedure using linq to sql.

stored procedure is

create procedure selecttempimage
@user_id bigint
as
begin
select user_image from Temp_Image where users_id=@user_id
end

linq to sql generated method is

[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.selecttempimage")]
    public ISingleResult<selecttempimageResult> selecttempimage([global::System.Data.Linq.Mapping.ParameterAttribute(DbType="BigInt")] System.Nullable<long> user_id)
{
IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), user_id);
return ((ISingleResult<selecttempimageResult>)(result.ReturnValue));
}

thanks in advance.

2
  • Do you need to do this specifically by LINQ to SQL ? I used similar field and got byte array in the Select SP, but not via LINQ Commented May 28, 2011 at 9:00
  • What is the signature of your LINQ-to-SQL method ?
    – driis
    Commented May 28, 2011 at 9:06

2 Answers 2

1

This should do it, if your Linq2Sql context is called MyDbDataContext:

using(var context = new MyDbDataContext())
{
    var byte_array = context.selecttempimage(user_id).SingleOrDefault();
    //...do something with byte_array
}
1
string givenId = "...";

var images = from Temp_Image in db.Users where users_id == givenId select user_image;

List<byte[]> image_byte_arr = new List<byte[]>();

foreach(image in images)
   image_byte_arr.Add((byte[])image.user_image);
2
  • Formatting Tip: once you indent 4 spaces (or one tab) there's no need for the backticks. Cheers mate. Keith.
    – corlettk
    Commented May 28, 2011 at 9:42
  • Ya.. somehow i wasnt getting the formatting, so applied the ticks. Now i see that it takes a while for formatting to show. :) Cheers! Commented May 28, 2011 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.