2013-07-10 80 views
1

我有幾個ef實體類(生成數據庫第一)。本人水平有限使用EF 3.5 我需要從倉庫接口返回一個常見的類型 - 試圖使用擴展在部分實體類,但沒有工作的自定義界面 -實體框架實體類返回的可能接口是什麼?

我的一些代碼:

庫接口:

interface IRepository 
{ 
    List<string> GetColumnNames(); 


    IQueryable<EntityObject> GetAll();//what common type/interface can I return here? 
} 

庫類: 我有幾個這些

class CatalogItemRepository:IRepository 
{ 
    private string repositoryName="CatalogItem"; 

    public List<string> GetColumnNames() 
    { 
     //implementation 
    } 
    public IQueryable<CatalogItem> GetAll() 
    { 
     //implementation 
    } 

} 

實體類

回答

2

通用存儲庫模式如何?

public interface IRepository<T> 
{ 
    List<string> GetColumnNames(); 

    IQueryable<T> GetAll(); 
} 

public class CatalogItemRepository : IRepository<CatalogItem> 
{ 
    private string repositoryName="CatalogItem"; 

    public List<string> GetColumnNames() 
    { 
     //implementation 
    } 

    public IQueryable<CatalogItem> GetAll() 
    { 
     //implementation 
    } 
}