コストが最初に発生する時期と、コストが何度も発生することを意味する繰り返し期間を年単位で指定したいと考えています。そこで、次のようなコスト モデルを作成しました。
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 を使用して、2 つの日付の間に発生したコストを返したいと考えています。
編集質問を単純化しすぎました。特定の日付と一定期間後に発生した PropertyCosts があります。費用の発生日は、物件調査日から算出します。コスト モデルは RepeatPeriod を格納し、特定の質問/回答に関連付けられています。物件に関して特定の方法で質問に回答した場合、費用が発生します。だから私はこのように見えるコードを持っています(まだここで単純化しようとしています)が、現時点では最初の出現しか得ていません
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
}