我有一个存储过程,它返回单列数据类型image.stored过程被添加到linq到sql class.how我可以使用linq到sql从存储过程创建字节数组。
存储过程是
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));
}
提前感谢。
答案 0 :(得分: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);
答案 1 :(得分:1)
如果您的Linq2Sql上下文被称为MyDbDataContext:
,这应该这样做using(var context = new MyDbDataContext())
{
var byte_array = context.selecttempimage(user_id).SingleOrDefault();
//...do something with byte_array
}