ASP.NET Framework无法获取其他模型的引用

时间:2019-08-25 12:37:22

标签: asp.net sql-server asp.net-mvc asp.net-identity

我有两种与情况有关的模型:

ApplicationUser(Identity Framework)和会议室,

这是“模型”文件夹中Room.cs的属性:

   public class Room
   {
        public int RoomId { get; set; }
        public string Name { get; set; }
        public int EnterPrice { get; set; }
        public int UserDecisionTime { get; set; }
        public virtual ICollection<Card> CardsDeck { get; set; }
        public virtual ICollection<Card> CardsOnTable { get; set; }
        public int WhosTurnChairNumber { get; set; }
        public string Chair0_Id { get; set; }
        public string Chair1_Id { get; set; }
        public string Chair2_Id { get; set; }
        public string Chair3_Id { get; set; }
        public string Chair4_Id { get; set; }
        public virtual ApplicationUser Chair0 { get; set; }
        public virtual ApplicationUser Chair1 { get; set; }
        public virtual ApplicationUser Chair2 { get; set; }
        public virtual ApplicationUser Chair3 { get; set; }
        public virtual ApplicationUser Chair4 { get; set; }
        public int Round { get; set; }
        public int PotOfChair0 { get; set; }
        public int PotOfChair1 { get; set; }
        public int PotOfChair2 { get; set; }
        public int PotOfChair3 { get; set; }
        public int PotOfChair4 { get; set; }
}

这就是房间作为桌子的样子:

CREATE TABLE [dbo].[Rooms] (
    [RoomId]              INT            IDENTITY (1, 1) NOT NULL,
    [Name]                NVARCHAR (MAX) NOT NULL,
    [EnterPrice]          INT            NOT NULL,
    [UserDecisionTime]    INT            NOT NULL,
    [WhosTurnChairNumber] INT            NOT NULL,
    [Round]               INT            NOT NULL,
    [PotOfChair0]         INT            NULL,
    [PotOfChair1]         INT            NULL,
    [PotOfChair2]         INT            NULL,
    [PotOfChair3]         INT            NULL,
    [PotOfChair4]         INT            NULL,
    [Chair0_Id]           NVARCHAR (MAX) NULL,
    [Chair1_Id]           NVARCHAR (MAX) NULL,
    [Chair2_Id]           NVARCHAR (MAX) NULL,
    [Chair3_Id]           NVARCHAR (MAX) NULL,
    [Chair4_Id]           NVARCHAR (MAX) NULL,
    [Chair0_Id1]          NVARCHAR (128) NULL,
    [Chair1_Id1]          NVARCHAR (128) NULL,
    [Chair2_Id1]          NVARCHAR (128) NULL,
    [Chair3_Id1]          NVARCHAR (128) NULL,
    [Chair4_Id1]          NVARCHAR (128) NULL,
    CONSTRAINT [PK_dbo.Rooms] PRIMARY KEY CLUSTERED ([RoomId] ASC),
    CONSTRAINT [FK_dbo.Rooms_dbo.AspNetUsers_Chair0_Id1] FOREIGN KEY ([Chair0_Id1]) REFERENCES [dbo].[AspNetUsers] ([Id]),
    CONSTRAINT [FK_dbo.Rooms_dbo.AspNetUsers_Chair1_Id1] FOREIGN KEY ([Chair1_Id1]) REFERENCES [dbo].[AspNetUsers] ([Id]),
    CONSTRAINT [FK_dbo.Rooms_dbo.AspNetUsers_Chair2_Id1] FOREIGN KEY ([Chair2_Id1]) REFERENCES [dbo].[AspNetUsers] ([Id]),
    CONSTRAINT [FK_dbo.Rooms_dbo.AspNetUsers_Chair3_Id1] FOREIGN KEY ([Chair3_Id1]) REFERENCES [dbo].[AspNetUsers] ([Id]),
    CONSTRAINT [FK_dbo.Rooms_dbo.AspNetUsers_Chair4_Id1] FOREIGN KEY ([Chair4_Id1]) REFERENCES [dbo].[AspNetUsers] ([Id]) );


GO CREATE NONCLUSTERED INDEX [IX_Chair0_Id1]
    ON [dbo].[Rooms]([Chair0_Id1] ASC);


GO CREATE NONCLUSTERED INDEX [IX_Chair1_Id1]
    ON [dbo].[Rooms]([Chair1_Id1] ASC);


GO CREATE NONCLUSTERED INDEX [IX_Chair2_Id1]
    ON [dbo].[Rooms]([Chair2_Id1] ASC);


GO CREATE NONCLUSTERED INDEX [IX_Chair3_Id1]
    ON [dbo].[Rooms]([Chair3_Id1] ASC);


GO CREATE NONCLUSTERED INDEX [IX_Chair4_Id1]
    ON [dbo].[Rooms]([Chair4_Id1] ASC);

现在,在会议室中,我有一种将用户添加到椅子的方法,例如,我可以:

SomeMethod(ApplicationUser user) {
    this.Chair0 = user;
}

(我也做db.SaveChanges()) 当我查看“视图”->“ SQL Server对象资源管理器”时,它确实将用户保存在Chair0_Id中,但是当我这样做时:

Room = db.Rooms.Find(id);

第一个ApplicationUser不在Room.Chair0中显示,为什么?

0 个答案:

没有答案