entity framework core one to many relationship code example

Example 1: entity framework core update one to many relationship

exec sp_executesql N'SET NOCOUNT ON;UPDATE [Books] SET [AuthorId] = @p0WHERE [BookId] = @p1;SELECT @@ROWCOUNT;',N'@p1 int,@p0 int',@p1=2,@p0=NULL

Example 2: one to many relationship ef core

// 1:M
// ONE company has MANY employees

public class Company
{
    public int Id { get; set; }
    public string Name { get; set; }
    public ICollection Employees { get; set; }
}
public class Employee
{
    public int Id { get; set; }
    public string Name { get; set; }
    public Company Company { get; set; }
}

Tags:

Misc Example