i have one method and it will return IQueryable value
public IQueryable<TabMasterViewModel> Query(Expression<Func<TabMaster, bool>> whereCondition)
{
IQueryable<TabMaster> tabmasters = _tabmasterRepository.GetQueryable().Where(whereCondition);
IQueryable<TabMasterViewModel> tabmasterview;
AutoMapper.Mapper.CreateMap<TabMaster, TabMasterViewModel>()
.ForMember(dest => dest.colID, opt => opt.MapFrom(src => src.colID));
tabmasterview = AutoMapper.Mapper.Map(tabmasters, tabmasterview);
return tabmasterview;
}
and the GetQueryable is like
public IQueryable<T> GetQueryable()
{
return this.ObjectSet.AsQueryable<T>();
}
but the following line
tabmasterview = AutoMapper.Mapper.Map(tabmasters, tabmasterview);
is giving me an error
Use of unassigned local variable ‘tabmasterview’
please suggest me, where is am i wrong?
To fix the compiler error all you have to do is
But the second argument you are passing to
AutoMapper.Mapper.Map(tabmasters, tabmasterview)is always null as tabMasterview has not been intialized. If that is intended you could as well pass “null”.EDIT:
The above code answers your question related to compiler error.
As for your comments about the runtime error.. modify this line
to