我有一个存储过程,它返回数据类型image的单列。存储过程被添加到linq-to-sql类中。如何使用linq-to-sql从存储过程创建字节数组。
存储过程是
create procedure selecttempimage
@user_id bigint
as
begin
select user_image from Temp_Image where users_id=@user_id
end
linq到sql生成的方法是
[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));
}
提前谢谢。
如果您的Linq2Sql上下文被称为MyDbDataContext:,则应该这样做
using(var context = new MyDbDataContext())
{
var byte_array = context.selecttempimage(user_id).SingleOrDefault();
//...do something with byte_array
}
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);