组织的几周和几天(Organising Weeks and Days)

2019-10-20 13:36发布

我想提出一个需要被组织成周,这是在组织成转年每天读数MVC应用程序。 我有一个星期的实体,一天实体,分别是周,天表。 有什么办法,我可以几天链接到WeekNo但没有WeekNoDayNo作为主键?

例如,会在1每周工作5天:

WeekNo = 1, DayNo = 1
WeekNo = 1, DayNo = 2
WeekNo = 1, DayNo = 3
WeekNo = 1, DayNo = 4
WeekNo = 1, DayNo = 5

然后,当第2周走来:

WeekNo = 1, DayNo = 1 

但随后有1天的副本。

我有一年与周类似的问题,当明年来临时,又回到了1周,有一个在周重复。 但是,如果我能得到过去,这,也许我就能够明白这一点了。

我怎么会去引用这些彼此?

Day模型:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Utility.Models
{
    public class Day
    {
        public int DayID { get; set; }
        public int WeekNo { get; set; }
        public int DayNo { get; set; }
        public string DayofWeek { get; set; }
        public float Reading1 { get; set; }
        public float Reading2 { get; set; }
        //etc

        public virtual Week Week { get; set; }

    }
}

Week模型:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations.Schema;

namespace Utility.Models
{
    public class Week
    {
        public int WeekID { get; set; }
        public int WeekNo { get; set; }
        public int YearID { get; set; }

        public virtual Year Year { get; set; }
        public virtual ICollection<Day> Days { get; set; }

    }
}

Answer 1:

如何多对多的关系?

public class Day
{
    public int DayID { get; set; }
    public int DayNo { get; set; }
    public virtual ICollection<WeekDay> WeekDays { get; set; }
}
public class Week
{
    public int WeekID { get; set; }
    public int WeekNo { get; set; }
    public virtual ICollection<WeekDay> WeekDays { get; set; }
}
public class WeekDay
{
    public int WeekDayID { get; set; }
    public int DayID { get; set; }
    public virtual Day Day { get; set; }
    public int WeekID { get; set; }
    public virtual Week Week { get; set; }
}


文章来源: Organising Weeks and Days