2014-10-08 74 views
1

我有以下實體:Graphdiff被刪除實體

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(); 
(...) 

有關它的任何想法?
謝謝!

回答

3

找到了解決辦法閱讀andypelzer的約美聯社之間的差異的解釋後並擁有在這個崗位:

https://github.com/refactorthis/GraphDiff/issues/43

因此,我改變

((BaseRepository)this.Repository) 
    .UpdateGraph(profile,map => map.OwnedCollection(p => p.Functionalities)); 
this.Repository.SaveChanges(); 

((BaseRepository)this.Repository) 
    .UpdateGraph(profile,map => map.AssociatedCollection(p => p.Functionalities)); 
this.Repository.SaveChanges(); 

和作品像一個魅力!