我的问题是,当我有以下 2 个查询时,第一个不填充 CampaignID 属性,但第二个填充。这是我的代码;
查询1;
var query = from c in _context.MCTargets
where c.TargetDateFrom==d1 && c.TargetDateTo<=d2
group c by c.MarketingCampaignID into g
select new MSReport{
CampaignID = g.Key, // CampaignID is not populated here.
StartDate = d1,
EndDate = d2
};
查询2;
var query2 = from c in _context.MCTargets
where c.TargetDateFrom == d1 && c.TargetDateTo <= d2
group c by c.MarketingCampaignID into g
select new
{
CampaignID = g.Key,
StartDate = d1,
EndDate = d2
};
MSReport.cs
public class MSReport
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
public int CampaignID { get; set; }
public MSReport()
{
// CampaignID = 0 here
// doing something with CampaignID here like setting some calculated properties.
}
}
在此先感谢并为我糟糕的解释感到抱歉。