C# 周和日实体

C# 周和日实体,c#,asp.net-mvc,entity-framework,C#,Asp.net Mvc,Entity Framework,我正在用ASP.NET学习C和MVC。我正在制作一个应用程序,它获取每日数据并将其拆分为几周 我的问题是:我应该如何制作实体?我想要它,这样你就有一个星期和一个星期,你用它们来显示,编辑和创建数据和表格。例如,WeekNo=1和DayNo=1将是第1周的星期一。WeekNo=1和DayNo=2将是星期二,依此类推 我是新手,不太擅长信息管理。我需要外键吗 我在想: public class Day { public int WeekNo { get; set; } public

我正在用ASP.NET学习C和MVC。我正在制作一个应用程序,它获取每日数据并将其拆分为几周

我的问题是:我应该如何制作实体?我想要它,这样你就有一个星期和一个星期,你用它们来显示,编辑和创建数据和表格。例如,WeekNo=1和DayNo=1将是第1周的星期一。WeekNo=1和DayNo=2将是星期二,依此类推

我是新手,不太擅长信息管理。我需要外键吗

我在想:

public class Day
{
    public int WeekNo { get; set; }
    public int DayID { get; set; }
    public int DayNo { get; set; }
    public string DayofWeek { get; set; }

    //then other declarations, not important

    [ForeignKey("DayNo")]
}

public class Week
{
    public int ID { get; set; }
    public int WeekNo { get; set; }
    public int DayofWeek { get; set; }
}
外键是在一天或一周内使用,还是我需要它?

假设您在说实体时是指对象

以下是如何构造每天使用的对象:

否则,您可以使用以下每周使用的结构:

如果本周已经存在此对象,您也可以从某处获取此对象

现在,每日目标:

//Declare the weekly object:
myWeeklyObject thisWeek = new myWeeklyObject();
//Populate variables of thisWeek here:
thisWeek.ObjectID = thisWeek.WeekNo = CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
//The line above gets the current weekNo for the year.
//Get the day of the week as an int:
int dayOfWeek = (int)DateTime.Now.DayOfWeek + 1; //DayOfWeek is 0 based
//Daclare object for a specific day:
myDataObject newObject = new myDataObject();
//Populate variables of newObject here.
//Then add it with the int dayOfWeek as the Key to the DataByDay Dictionary.
thisWeek.DataByDay.Add(dayOfWeek, newObject);
我希望这能回答你的问题和未来的问题,比如如何获得周末,或者至少对你有所帮助


祝你好运。

你对实体到底是什么意思?代码中的对象?视图中的元素?数据库中的表?还有,您希望每天或每周都有一个实例吗?好的,我发布了我的答案,如果您是指代码中的对象,每周和每天都有。希望对你有帮助,教授,我对这个很陌生。我的意思是数据库中的表。你的答案也适用于他们吗?我希望能够点击一周,它会显示所有的日子,然后当我选择一天时,它会显示当天的读数。
//Declare the weekly object:
myWeeklyObject thisWeek = new myWeeklyObject();
//Populate variables of thisWeek here:
thisWeek.ObjectID = thisWeek.WeekNo = CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(DateTime.Now, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
//The line above gets the current weekNo for the year.
//Get the day of the week as an int:
int dayOfWeek = (int)DateTime.Now.DayOfWeek + 1; //DayOfWeek is 0 based
//Daclare object for a specific day:
myDataObject newObject = new myDataObject();
//Populate variables of newObject here.
//Then add it with the int dayOfWeek as the Key to the DataByDay Dictionary.
thisWeek.DataByDay.Add(dayOfWeek, newObject);