想象我有两个实体:如何将EF CodeFirst多重性从一个更改为零?
实体在“SLContext:
public class User{ public Guid UserId { get; set; } } public class Country{ public Guid CountryId {get; set;} public virtual List<User> Users {get; set;} }
如果我尝试添加谁不属于任何国家的用户,我对
SaveChanges
命令得到UpdateException
用户'参与'Country_Users' 的关系。找到0条相关'Country_Users_Source'。 1 'Country_Users_Source'is expected
我认为这个问题与自动生成的一对多关系有关。我怎样才能将这个多重性设置为0.1 ---> *?
你在用什么做Mapping? FluentAPI或DataAnnotation? – saber