我有以下实体:
public class Profile
{
[Required]
public string Name { get; set; }
[Required]
public string Description { get; set; }
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
public IList<Functionality> Functionalities { get; set; }
}
和
public class Functionality
{
[Required]
public string Name { get; set; }
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int ID { get; set; }
}
在我的服务方法中,当我尝试以下操作时,它会从数据库中删除不在配置文件功能列表中的功能对象:
(...)
var databaseFunctionalities = this
.Repository
.GetByIds<Functionality>(profile
.Functionalities
.ToIdList());
profile.Functionalities.Clear();
profile.Functionalities.AddRange(databaseFunctionalities);
((BaseRepository)this.Repository)
.UpdateGraph(profile,map => map.OwnedCollection(p => p.Functionalities));
this.Repository.SaveChanges();
(...)
有什么想法吗?
谢谢!