组织周和日

时间:2014-07-24 09:47:09

标签: sql asp.net-mvc asp.net-mvc-5

我正在制作一个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; }

    }
}

1 个答案:

答案 0 :(得分: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; }
}