准备三个Model
League
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Text;
namespace Demo.Domain
{
public class League
{
public int Id { get; set; }
[Required]
[MaxLength(100)]
public string Name { get; set; }
[Required,MaxLength(100)]
public string Country { get; set; }
}
}
Club
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
namespace Demo.Domain
{
public class Club
{
public Club()
{
Players = new List<Player>();
}
public int Id { get; set; }
public string Name { get; set; }
public string City { get; set; }
[Column(TypeName ="date")]
public DateTime DateOfEstablishment { get; set; }
public string History { get; set; }
public League League { get; set; }
public List<Player> Players { get; set; }
}
}
Player
using System;
using System.Collections.Generic;
namespace Demo.Domain
{
public class Player
{
public Player()
{
GamePlayers = new List<GamePlayer>(); //避免空指针异常
}
public int Id { get; set; }
public string Name { get; set; }
public DateTime DateOfBirth { get; set; }
public List<GamePlayer> GamePlayers { get; set; }
//与Resume建立一对一的关系
public int ResumeId { get; set; }
public Resume Resume { get; set; }
}
}