c# - 选择 Linq 无法将类型 byte[] 隐式转换为 System.web.httpPostedFileBase
问题描述
我正在尝试做一个 linq 选择,它连接多个表,并且表中的 1 个由字节数据类型组成。
我的 ViewModel 如下:
public class ServiceRequestsViewModel
{
public HttpPostedFileBase Attachment { get; set; }
}
我的控制器如下:
public IEnumerable<ServiceRequestsViewModel> ServiceRequestGetAll()
{
var result = (from srv in DB.Services
join srq in DB.ServiceRequests on srv.Id equals srq.ServiceId
join srp in DB.ServiceApprovers on srq.ServiceId equals srp.ServiceId
select new ServiceRequestsViewModel
{
Id = srq.Id,
ServiceId = srq.ServiceId,
RequestorId = srq.RequestorId,
ApproverId = srp.UserId,
Name = srv.Name,
Description = srq.Description,
Status = srq.Status,
Attachment = srq.Attachment,
CreatedBy = srq.CreatedBy,
CreatedDate = srq.CreatedDate
})
;
return result.GroupBy(x => x.Id).Select(group => group.FirstOrDefault()).OrderByDescending(a => a.Status).ThenByDescending(b => b.CreatedDate);
}
对于 Attachment = srq.Attachment,我遇到错误:无法将类型 byte[] 隐式转换为 System.Web.HttpPostedFileBase。
解决方案
HttpPostedFileBase
是一个包装类,因此您可以访问客户端通过此调用上传的数据。
你的电话不在那种情况下。
您的数据已经在您的数据库中。您需要选择不同的数据类型来将该数据返回给您的客户端。byte[]
(您已经拥有)可能适合您的情况,我们不知道,这是您的工作来决定。
推荐阅读
- android - 在 Android 上实现可恢复调度程序的正确方法是什么?
- c++ - 如何检查n个给定图块中的任何一个是否重叠
- code-documentation - YARD doc - how to document a class type focusing on its parent class
- ruby - 代码没有检查 ruby 中的第二个 elsif 条件
- c# - 如何在 ASP.NET MVC 中使用会话 ID 获取会话详细信息
- javascript - 如何在通过“最佳位置”编辑进行内联编辑时删除 html 标签
- c++ - logb() 和 ilogb() 有什么区别?
- javascript - 如何检查文件下载是否在 Chrome 中完成?
- javascript - 如何调用嵌套在表格单元格中的textarea属性?
- mysql - Map.prototype.forEach 不迭代 Map