C# Linq结果在ASP.NET MVC控制器的ViewModel中转换为IEnumerable

C# Linq结果在ASP.NET MVC控制器的ViewModel中转换为IEnumerable,c#,asp.net-mvc,linq,C#,Asp.net Mvc,Linq,我试图将我的linq查询结果放入视图模型中,但我一直得到一个错误。Linq查询返回多个评级结果。我想把这些多重评级结果放在一个IEnumerable中 错误:无法将类型模型.CustomerRating'隐式转换为'System.Collections.Generic.IEnumerable'。存在显式转换(是否缺少强制转换?) Linq查询 var data = from profile in _context.Customers join rating in _cont

我试图将我的linq查询结果放入视图模型中,但我一直得到一个错误。Linq查询返回多个评级结果。我想把这些多重评级结果放在一个IEnumerable中

错误:无法将类型模型.CustomerRating'隐式转换为'System.Collections.Generic.IEnumerable'。存在显式转换(是否缺少强制转换?)

Linq查询

var data = from profile in _context.Customers
           join rating in _context.CustomerRating
                on profile.strUserID equals rating.strUserID into rt
           from subrating in rt.DefaultIfEmpty()
           where profile.strUserID == UserId
           select new { p = profile, r = subrating };
我的视图模型:

public class ServiceProvider
{
    public CustomerProfile Customer { get; set; }

    public IEnumerable<CustomerProfile> CustomerProfiles { get; set; }
    public CustomerServices CustomerServices { get; set; }

    public FilterServicesViewModel FilterServices { get; set; }

    public CustomerRating Rating { get; set; }

    public IEnumerable<CustomerRating> CustomerRating { get; set; }
}

创建一个新列表,循环linq查询结果并将其添加到该列表中

    List<CustomerRating> RatingList = new List<CustomerRating>();
            foreach (var v in data)
            {
                serviceProviderViewModel.Customer = v.p;
                RatingList.Add(v.r); 
            }
            serviceProviderViewModel.CustomerRating = RatingList;
List RatingList=newlist();
foreach(数据中的var v)
{
serviceProviderViewModel.Customer=v.p;
比率列表。添加(v.r);
}
serviceProviderViewModel.CustomerRating=RatingList;
    List<CustomerRating> RatingList = new List<CustomerRating>();
            foreach (var v in data)
            {
                serviceProviderViewModel.Customer = v.p;
                RatingList.Add(v.r); 
            }
            serviceProviderViewModel.CustomerRating = RatingList;