2015-03-03 157 views
0

我有一个基本的API控制器,这里是一个片段:无法覆盖ApiController方法

public abstract class CrudController<TDto, TAdd, TEdit, TLookup> : BaseApiController 
     where TDto : BaseDto, new() 
     where TAdd : BaseModel 
     where TEdit : BaseModel 
     where TLookup : BaseModel 
    { 
     [NonAction] 
     protected virtual Expression<Func<TDto, bool>> CreateWhere(Guid? id) 
     { 
      return dto => true; 
     } 

     [HttpGet] 
     public virtual DataSet<TLookup> Query([FromUri] DtoQuery query, Guid? id = null) 
     {   
      DataSet<TDto> data = DataService.Query(query, CreateWhere(id)); 
      return new DataSet<TLookup>(data.Records.Map<TLookup>(), data.Total); 
     } 
    } 

我从这个ApiController类继承,然后希望重写一个方法,在派生类中:

public class ProductCategoryController : CrudController<ProductSubcategoryDto, ProductSubcategoryModel, ProductSubcategoryModel, ProductSubcategoryModel> 
{ 
    protected override Expression<Func<ProductSubcategoryDto, bool>> CreateWhere(Guid? id) 
    { 
     return dto => dto.ProductCategoryGuid == id; 
    } 
} 

但在派生类中的方法没有被执行。

获取API/productcategorycontroller /查询?queryetctectec从视图中调用。

数据集<>()是在基类执行。

然后我通过代码,该方法的第一行调用CreateWhere()和F11带我几行向上,而不是在派生类重写的方法。

BaseApiController仅仅是从ApiController派生的空类。

+0

是否执行基类中的方法?完全执行“CreateWhere”函数的* call *函数吗? – 2015-03-03 00:30:57

+0

什么是“BaseApiController”? – 2015-03-03 00:33:53

+0

你有没有试过不使用你的空班?尝试直接使用'ApiController' – 2015-03-03 00:58:09

回答

0

原来我打破了错误的ApiController,并且它一直工作。