I can't use this code because Member isn't available in the UI.
public MemberViewModel GetSingle(Expression<Func<Member ,bool>> whereCondition )
{
var member = this.MemberRepository.GetSingle( whereCondition );
if (member != null)
{
return new MemberViewModel( member );
// or however you map from member to its view model
}
return null;
}
What would a custom class look like to replace the expression? It would flow like this...
public MemberViewModel GetSingle(CustomClass where)
{
// Create customExp of type Expression<Func<DAL.EntityModels.Category,
// bool>> out of CustomObject
// _categoryRepository.GetSingle(customExp);
// Convert the resulting dataobject to corresponding view object
// return the view object
}
Any help appreciated.
Could you use something similar to this and then call it from somewhere that has access to both T (Member) and TViewModel (MemberViewModel)?
public static TViewModel GetSingle<T, TViewModel, TRepository>(Expression<Func<T, bool>> whereCondition, TRepository repository)
where T : class, Entity
where TViewModel : class, IViewModel<T>, new()
where TRepository : IRepository<T>
{
T member = repository.GetSingle(whereCondition);
if (member != null)
{
return new TViewModel().MapFrom(member);
// or however you map from member to its view model
}
return null;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.