-1
db.Images.Select(image => new ImageViewModel{
Image64 = //I want to make calcuation on the image.Uri to convert it toBase64
});
我会下载图像,并将其转换为Base64然后将其分配到ImageViewModel
的Image64
财产。 有没有办法做到这一点?
编辑
我尝试以下 Image64 = FromAzureToBase64(image.AzureUri),
它抛出这个异常:
其他信息:LINQ到实体无法识别方法 “System.String FromAzureToBase64(System.String )'方法,而这个方法不能被翻译成商店表达式。
这是方法(未测试):
private static string FromAzureToBase64(string azureUri)
{
Uri blobUri = new Uri(azureUri);
CloudBlockBlob blob = new CloudBlockBlob(blobUri, StorageAccount.Credentials);
using (MemoryStream stream = blob.OpenRead() as MemoryStream)
{
byte[] arr = stream.ToArray();
var azureBase64 = Convert.ToBase64String(arr);
return azureBase64;
}
}
你的职责是什么你尝试过这么远吗?我的意思是,它就像db.Images.Select(x => new {A = 1 * 5})一样简单;''例如。你甚至可以调用其他方法,如'A = GetSomeValue(x)' –
我修改了这个问题 –