User395582331 posted
I have a one-to-many relationship between LAs and LAApplications where the primary key of LAs is used as the foriegn key of LAApplications as a way of keeping track of who submits an application.
In my LA model I have a line to declare this relationship
public virtual ICollection<LAApplication> LAApplications { get; set; }
My LAs SQL Creatle table looks like
CREATE TABLE [dbo].[LAs] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[FirstName] NVARCHAR (MAX) NULL,
[LastName] NVARCHAR (MAX) NULL,
[UID] NVARCHAR (8) NULL,
[UserId] NVARCHAR (MAX) NULL,
CONSTRAINT [PK_LAs] PRIMARY KEY CLUSTERED ([Id] ASC)
);
My LAApplications SQL Creatle table looks like
CREATE TABLE [dbo].[LAApplications] (
[LAApplicationId] INT IDENTITY (1, 1) NOT NULL,
[SubmissionDate] DATETIME2 (7) NOT NULL,
[Semester] NVARCHAR (6) NULL,
[Year] INT NOT NULL,
[Status] NVARCHAR (MAX) NULL,
[Score] INT NOT NULL,
[LAId] INT NULL,
CONSTRAINT [PK_LAApplications] PRIMARY KEY CLUSTERED ([LAApplicationId] ASC),
CONSTRAINT [FK_LAApplications_LAs_LAId] FOREIGN KEY ([LAId]) REFERENCES [dbo].[LAs] ([Id])
);
Yet when I'm in the LAApplicationController and I'm looking for all LAApplications submitted by a certain LA, i.e. by saying
int currentLAId = some number;
return View(await _context.LAApplications.Where(x => x.LAId == currentLAId).ToListAsync());
Also for my modelBuilder, for these two I have
modelBuilder.Entity<LA>()
.HasKey(l => new { l.Id });
modelBuilder.Entity<LAApplication>()
.HasKey(la => new { la.LAApplicationId });
The LAApplications.LAId doesn't show up as an option even though I can see its in the database and is a foreign key. Does anyone know what's going on?