2013-04-17 35 views
2

我的問題是類似這樣的帖子: Interface inheritance in Entity Framework實體框架:擴展與接口部分類不接觸EF-生成的類

因此,我複製例子並修改它爲我的問題:

public interface IBaseEntity 
{ 
    DateTime CreatedOn { get; set; } 
    string CreatedBy { get; set; } 
} 

// The following two classes are generated by Entity Framework 
public partial class SomeEntity 
{ 
    public int SomeEntityId { get; } 
    public string Name { get; set; } 
    public DateTime CreatedOn { get; set; } 
    public string CreatedBy { get; set; } 
} 

public partial class OtherEntity 
{ 
    public int OtherEntityId { get; } 
    public float Amount { get; set; } 
    public DateTime CreatedOn { get; set; } 
    public string CreatedBy { get; set; } 
} 


我想什麼做的是以下幾點:

public partial class SomeEntity : IBaseEntity 
    { 
     // No code needed here because the other partial class 
     // already has the needed properties 
    } 

但那麼我得到以下錯誤:

Error 64 '[...].SomeEntity' does not implement interface member '[...]IBaseEntity.CreatedOn' 
Error 64 '[...].SomeEntity' does not implement interface member '[...]IBaseEntity.CreatedBy' 

很明顯,我也可以看到。
但我認爲編譯後,部分類將成爲一個,以便編譯器不應該抱怨。

任何想法?

在此先感謝!

+1

在同一命名空間中執行這些類嗎? – Nagg

+0

其實,這是困難點,我只是將第二個提到的部分類的名稱空間路徑更改爲生成的部分類和編譯器現在不再抱怨了 –

+0

所以這只是一個命名空間問題,因爲我有一個非常相似的情況,它工作得很好,因爲我的部分與EF生成的對象在同一個命名空間中。接口,只是實現了部分類的接口,它工作得很好。 – Charles380

回答

-1

我有同樣的錯誤,我解決了在App_Code文件夾之外移動部分類! 我應該承認,我不明白原因:-(

+0

這是一個沒有意義的答案。我們不知道你的App_Code文件夾,並且移動的類不需要只能改變他們的命名空間(這是問題)。 –

+0

你不明白。這是一個網站,你現在應該是什麼app_code文件夾。如果你現在沒有,請不要寫任何東西 –

+0

我知道app_code是什麼。我不知道你的app_code。而且,我們甚至不知道OP的代碼是否在app_code文件夾附近。 –