我想从我的域模型中选择某些字段,并按域模型中的一个字段进行分组,然后将结果放入 ViewModel - 但是,我无法正确获取 Linq 语法。
我的模型是:
public class Offer
{
public int OfferId { get; set; }
public string Inclusions { get; set; }
public string Property { get; set; }
public bool IncludeInOffer { get; set; }
public Guid guid { get; set; }
public int NumPeople { get; set; }
public int NumNights { get; set; }
public DateTime ArrivalDate { get; set; }
public string CustomerName { get; set; }
public string EmailAddress { get; set; }
public DateTime OfferCreatedOn { get; set; }
public string Email { get; set; }
public string OfferReference { get; set; }
}
我的视图模型是:
public class OfferVMList
{
public string guid { get; set; }
public int NumPeople { get; set; }
public int NumNights { get; set; }
public DateTime ArrivalDate { get; set; }
public string CustomerName { get; set; }
public string EmailAddress { get; set; }
public DateTime OfferCreatedOn { get; set; }
public string Email { get; set; }
public string OfferReference { get; set; }
}
我的 Linq 是:
OfferVMList item = db.Offers
.GroupBy(x => x.OfferReference)
.Select(ct => new OfferVMList
{
NumPeople = ct.NumPeople
})
.OrderBy(x => x.ArrivalDate);
但是,错误消息是:
System.Linq.IGrouping<string,FGBS.Models.Offer>' does not contain a definition for 'NumPeople' and no extension method 'NumPeople' accepting a first argument of type 'System.Linq.IGrouping<string,FGBS.Models.Offer>' could be found (are you missing a using directive or an assembly reference?)
'
谁能看到我要去哪里错了?
谢谢