我是 asp.net MVC4 和 EntityFramework 的新手。
尝试向 API 添加新方法时出现此错误:
LINQ to Entities 仅支持无参数构造函数和初始值设定项。
这是我的方法:
// GET: api/Partenaires_prestations
[Authorize]
[Route("api/Partenaires_prestations")]
public List<PartenaireMapItem> GetPartenairesWithPrestations()
{
Random rnd = new Random();
var queryString = Request.GetQueryNameValuePairs();
var prestation = queryString.FirstOrDefault();
return db.Partenaires
.Where(p => p.PartenairePrestations.Any(pp => pp.Prestation.NomPrestation == prestation.Value))
.Select(p => new PartenaireMapItem {
IdPartenaire = p.IdPartenaire,
FirstName = p.FirstName,
LastName = p.LastName,
NomComplet = p.LastName.Substring(0,1).ToUpper() + ". " + p.FirstName,
Type = p.Type,
DureeMin = 50,
Lat = p.Lat,
Lng = p.Lng,
ImageUrl = p.ImageUrl,
SeDeplace = p.SeDeplace,
ADomicile = p.ADomicile,
NoteGlobale = p.NoteClientPartenaires.Sum(x => ((double)(x.NoteAimabilite + x.NotePonctualite +
x.NoteProprete + x.NoteQualite)) / 4) / p.NoteClientPartenaires.Count,
Prestations = new List<string>(p.PartenairePrestations.Select(y => y.Prestation.NomPrestation))
}).ToList();
}
慕码人8056858
犯罪嫌疑人X
梦里花落0921
相关分类