简体   繁体   English

选择Linq不能将类型byte []隐式转换为System.web.httpPostedFileBase

[英]Select Linq cannot implicitly convert type byte[] to System.web.httpPostedFileBase

I am trying to do a linq select which join multiple table and 1 of the table consist of a byte data type. 我试图做一个linq select联接多个表和表的1组成一个字节数据类型。

My ViewModel is as per below: 我的ViewModel如下所示:

public class ServiceRequestsViewModel
{
    public HttpPostedFileBase Attachment { get; set; }
}

My controller is as per below: 我的控制器如下:

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);
    }

For the Attachment = srq.Attachment, I encounter the error: Cannot implicitly convert type byte[] to System.Web.HttpPostedFileBase. 对于Attachment = srq.Attachment,我遇到了错误:无法将类型byte []隐式转换为System.Web.HttpPostedFileBase。

HttpPostedFileBase is a wrapper class so you can access the data that your client uploaded with this call . HttpPostedFileBase是包装器类,因此您可以访问客户端通过此调用上传的数据。

You are not in that scenario with your call. 您不在那种情况下。

Your data is already in your database. 您的数据已经在数据库中。 You need to pick a different datatype to return that data to your client. 您需要选择其他数据类型以将该数据返回给客户端。 byte[] (that you already have) might be fine for your case, we cannot know, that's your job to decide. byte[] (您已经拥有)可能适合您的情况,我们不知道,这是您要决定的工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 是否可以将单个System.Web.HttpPostedFileBase图像(任何类型)转换为位图对象? - Is it possible to convert a single System.Web.HttpPostedFileBase image (any type) to a bitmap object? 无法从程序集 System.Web 加载类型“System.Web.HttpPostedFileBase” - Could not load type 'System.Web.HttpPostedFileBase' from assembly System.Web 无法将类型&#39;system.linq.iqueryable匿名类型#1&#39;隐式转换为byte [] - cannot implicitly convert type 'system.linq.iqueryable anonymous type#1' to byte[] 如何通过将字符串转换为System.Web.HttpPostedFileBase将图像保存在db中 - How to save Image in db by converting string to System.Web.HttpPostedFileBase 无法将HttpPostedFileBase转换为Byte [] - Cannot convert HttpPostedFileBase to Byte[] 无法隐式转换类型&#39;System.Linq.IOrderedEnumerable <System.Web.Mvc.SelectListItem> &#39;到&#39;System.Web.Mvc.SelectList&#39; - Cannot implicitly convert type 'System.Linq.IOrderedEnumerable<System.Web.Mvc.SelectListItem>' to 'System.Web.Mvc.SelectList' 无法将类型'System.Linq.IQueryable <int>'隐式转换为'int?' - Cannot implicitly convert type 'System.Linq.IQueryable<int>' to 'int?' 无法隐式转换System.Linq.IQueryable类型 <string> 串起来 - Cannot implicitly convert type System.Linq.IQueryable<string> to string 无法隐式转换类型&#39;System.Linq.IQueryable? - Cannot implicitly convert type 'System.Linq.IQueryable? MVC 5无法将类型&#39;System.Linq.IQueryable隐式转换为bool吗? - MVC 5 Cannot implicitly convert type 'System.Linq.IQueryable to bool?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM