2014-09-04 95 views
0

這裏是我的數據庫模型類的時候我要選擇刪除相關記錄我得到「值不能爲null.Parameter名:源」值不能爲空。參數名:源

[Table("EkranKullanicisiKisitlama")] 

    public class EkranKullanicisiKisitlama : ISimpleEntity<long> 
    { 
     public long ID { get; set; } 
     public string KurumVKn { get; set; } 
     public string SaticiKurum { get; set; } 
     public bool Flag { get; set; } 
    } 
`(child_set as DbSet<ISimpleEntity<long>>)` 

child_set是實體並且它變滿當試圖嘗試投DbSet時它返回null

adr = (child_set as DbSet<ISimpleEntity<long>>).FirstOrDefault(p => p.ID == ID) as T; 
+0

可以添加錯誤的'堆棧trace'的DbSet? – Loetn 2014-09-04 14:26:07

+0

堆棧跟蹤是emtpy。我只能說當它投射到DbSet >它會返回null – altandogan 2014-09-05 05:44:31

回答

0

EF不能與接口一起使用。 DbSet必須與真正的實體實施

定義,你可以使用泛型類

嘗試context.Set<T>()讓你的實體

T adr = context.Set<T>().FirstOrDefault(p => p.ID == ID); 
相關問題