How can I use EF Code First to declare a one-to-many relationship?

前端 未结 2 1446
走了就别回头了
走了就别回头了 2021-02-06 09:08

I\'m trying to define a simple one-to-many relationship between two poco\'s, using the Entity Framework fluent API.

~ Team ~
public int TeamId {          


        
2条回答
  •  失恋的感觉
    2021-02-06 09:28

    I've been able to get this to work automatically simply by doing something like this:

     public class Team {
        public int TeamId { get; set; }
        ...
        public virtual ICollection Players { get; set; }
    }
    

    But you'll have to be more specifical about what exactly you mean when you say "doesn't work". What doesn't work, exactly? Are you getting an error message? If so, what is it? Is the Team property of the Player object always returning null?

提交回复
热议问题