我的WebAPI方法:表达<Func键<T, bool>>谓词两种类型
public async Task<MerchantViewModel> Get(string externalId)
{
return await _service.Get(m => m.ExternalId == externalId);
}
我有IService:
public interface IService<T>
where T : class
{
Task<T> Get(Expression<Func<T, bool>> predicate);
Task<IEnumerable<T>> GetAll(Expression<Func<T, bool>> predicate = null);
void Add(T viewModel);
void Delete(string id);
void Update(T viewModel);
}
而且IMerchantService:
public interface IMerchantService : IService<MerchantViewModel>
{
}
实现与方法:
public class MerchantService : IMerchantService { // ...
public async Task<IEnumerable<MerchantViewModel>> GetAll(Expression<Func<MerchantViewModel, bool>> predicate = null)
.. //
}
哪里T
是MerchantViewModel
,我有资源库和方法:
public async Task<IEnumerable<Merchant>> GetItemsAsync(Expression<Func<Merchant, bool>> predicate = null)
哪里T
是Merchant
。
现在我想要做这样的事情:
public async Task<MerchantViewModel> Get(Expression<Func<MerchantViewModel, bool>> predicate)
{
var domainMerchant = this._repository.GetItemAsync(predicate)
}
我可怎么办呢?
Merchant和MerchantViewModel具有相同的属性。 ViewModel有更多的东西。
添加另一个重载或传递替换商品类型与通用T –
方法签名中的T是哪里?前两个方法返回多个对象。最后一种方法似乎想要返回一个对象。这是不是很清楚你在问什么。 –
尝试检查这一个http://stackoverflow.com/questions/18337692/entity-framework-filter-expressionfunct-bool –