我想指定首次产生成本的时间以及以年为单位的重复周期,这意味着成本会一次又一次地产生。所以我创建了一个如下所示的成本模型:
public class Cost
{
public Cost()
{
Year = 1;
}
public decimal Amount { get; set; }
public int AnsweredQuestionID { get; set;}
public virtual AnsweredQuestion AnsweredQuestion {get; set;}
public int? RepeatPeriod { get; set; }
}
现在我想返回两个日期之间产生的费用,最好使用 Linq。
编辑我过度简化了我的问题。我有在特定日期和一段时间后再次发生的 PropertyCosts。首次发生成本的日期是从物业被调查之日起计算的。成本模型存储重复周期并与特定问题/答案相关。如果某个问题以特定方式回答了某项财产,则会产生费用。所以我的代码看起来有点像这样(仍然试图在这里简化)但目前我只得到第一次出现
public IEnumerable<PropertyCost> GetCosts(DateTime startDate, DateTime endDate)
{
IQueryable<AnsweredQuestion> answeredQuestions =
_Uow.AnsweredQuestionRepository
.All
.Where(x => x.PropertySurvey.PropertyID == id);
IQueryable<Cost> allCosts = UOW.CostRepository.All;
IQueryable<PropertyCost> firstOccurences = from aq in answeredQuestions
from c in costs
where aq.ID == c.AnsweredQuestionID
select new PropertyCost
{
QuestionText = aq.Question.Text,
AnswerText = aq.Answer.Text,
UnitCost = c.Amount,
Date = aq.PropertySurvey.Survey.StartDate,
RepeatYears = c.RepeatPeriod
});
//but now I need to insert PropertyCosts for recurring costs that occur when RepeatPeriod is not null
}