为什么不这样做:
public class Team {
public int Id { get; set; }
public virtual ICollection<Player> Players { get; set; }
}
public class Level {
public int Id { get; set; }
public virtual ICollection<Player> Players { get; set; }
}
public class Player {
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Team> Teams { get; set; }
public virtual ICollection<Level> Levels { get; set; }
}
如果你真的想 '重量轻'(请不要),你可以这样做:
public class Player {
public int Id { get; set; }
public string Name { get; set; }
//use comma separated values (starting and ending with ,)
public string Teams { get; set; }
public string Levels { get; set; }
}
说你有这些你背景
var player1 = new Player(){Teams = ",1,2,"}
var player2 = new Player(){Teams = ",3,2,"}
现在,你可以同时得到t eam 2 by
var players = context.Players.Where(p=>p.Teams.Contains(",2,"));
您不能将int作为映射到表的实体。 – 2014-10-16 11:34:37
为什么会有额外的表格?你没有定义它们,或者至少没有在你的代码中显示它们。 – Maarten 2014-10-16 11:34:48