是新手,请原谅我。
我有一个带有“ UserId”列的用户表,此“ UserId”是另一个表“日历表”的外键。如何从日历控制器发送发布方法以将UserId从用户表发布到日历表?
dbo.calendar
[FileLength] BIGINT NOT NULL,
[CreationTime] DATETIME NOT NULL,
[LastUpdatedOn] DATETIME NULL,
[UserId] NVARCHAR (128) NOT NULL,
[ApplicationUser_Id] NVARCHAR (128) NULL,
CONSTRAINT [PK_dbo.CalendarTables] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_dbo.CalendarTables_dbo.User_ApplicationUser_Id] FOREIGN KEY ([ApplicationUser_Id]) REFERENCES [dbo].[User] ([Id]),
CONSTRAINT [FK_dbo.CalendarTables_dbo.User_UserId] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id])
dbo.users
[LockoutEnabled] BIT NOT NULL,
[AccessFailedCount] INT NOT NULL,
[UserName] NVARCHAR (256) NOT NULL,
[UserId] NVARCHAR (MAX) NULL,
CONSTRAINT [PK_dbo.User] PRIMARY KEY CLUSTERED ([Id] ASC)
日历控制器
// POST api/value
[AllowAnonymous]
[ResponseType(typeof(CalendarTable))]
public IHttpActionResult PostCalendar(CalendarTable calendarTable)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
db.CalendarTables.Add(calendarTable);
db.SaveChanges();
return CreatedAtRoute("DefaultApi", new { id = calendarTable.Id }, calendarTable);
}
我只需要一种方法或方法,即可在发出发布请求时将特定用户“ UserId”从用户表发布到日历表的“ UserId”。谢谢