Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VS 2013 can not evaluate expression
Message
From
08/08/2014 15:59:16
 
General information
Forum:
ASP.NET
Category:
Troubleshooting
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01605242
Message ID:
01605354
Views:
42
This message has been marked as a message which has helped to the initial question of the thread.
>>>>Without knowing more detail on the layers it's hard to say. But I'd be inclined to leave the base class alone. If you do that you could simply add an additional method to the child class. So given an implicit cast to 'ShortOperator' you could just add a method:
public IEnumerable<ShortOperator> GetAllShortOperators()
>>>> {
>>>>     return  _operatorRepository.GetAll().Select((x => (ShortOperator)(x)));
>>>>  }
>>>
>>>
>>>I got this
>>>
>>>
>>>public IEnumerable<OperatorList> GetAllOperatorsList()
>>>        {
>>>            return _operatorRepository.GetAll().
>>>                Select((o=> new OperatorList{ OpCode = o.OpCode, 
>>>                    FirstName = o.FirstName, LastName = o.LastName, 
>>>                    Hidden = o.Hidden, OpCodeHash = o.OpCodeHash })
>>>                           );
>>>        }
>>>
>>>but not sure how to create a similar method for PagedResult
>>>
>>> //public PagedResult<OperatorList> GetOperators(QueryRequest queryRequest)
>>>        //{
>>>        //    return _operatorRepository.GetPagedRequest(queryRequest).Select((x=> (OperatorList)(x)));
>>>        //}
>>>
>>>as GetPagedRequest doesn't have Select method.
>>
>>Can't you add the select to _operatorRepository or queryRequest?
>
>Not really, as the implementation of that method is the following:
>
>
> public override PagedResult<Operator> GetPagedRequest(QueryRequest queryRequest)
>        {
>            PagedResult<Operator> pagedResult;
>
>            // Filter the operators by role number (if necessary).
>            // We do this here because Dynamic LINQ (which is being 
>            // used to filter all search queries in QueryHelper method
>            // GetFilteredQuery) cannot filter on the entity collections
>            // of the entity that is being filtered.  In other words, we 
>            // cannot filter on the SecMbrs collection of the Operator 
>            // entity with the Dynamic LINQ library being used in this 
>            // project.
>
>            if (queryRequest.FilterInfo.RoleNoFilter != 0)
>            {
>                SysManagerContext db = (SysManagerContext)_context;
>                var query = db.Operators.Where(o => o.SecMbrs.Any(sm => sm.RoleNo == queryRequest.FilterInfo.RoleNoFilter));
>                query = QueryHelper.GetFilteredQuery<Operator>(query, queryRequest);
>                pagedResult = QueryHelper.GetPagedResult(query, queryRequest);
>            }
>            else
>            {
>                pagedResult = base.GetPagedRequest(queryRequest);
>            }
>
>            foreach (var op in pagedResult.List)
>            {
>                HashOpCode(op);
>            }
>            return pagedResult;
>        }
>
>I think I have no choice as to create a clone of that method directly in the repository.
>
>I think the last foreach already converts the above into the list and executes the query.
>
>-----------------------------------
>I am also thinking - would it be nice to have something more generic. Say, instead of creating the light weight class I would just pass column names as a string or dictionary or something and have it create that object.
>
>Do you see how this would be possible if the base repository class is the following:
>
>
> public abstract class RepositoryBase<T> : IRepository<T> where T : class
>    {
>        protected readonly ISysManagerContext _context;
>        protected readonly IDbSet<T> _dbSet;
>        private readonly IExceptionParser _exceptionParser;
>
>        public RepositoryBase(ISysManagerContext context)
>        {
>            _context = context;
>            _dbSet = _context.Set<T>();
>            _exceptionParser = new ExceptionParser();
>        }
>
>        public virtual IEnumerable<T> GetAll()
>        {
>            return _dbSet;
>        }        
>
>        public virtual IEnumerable<T> GetAll(params string[] includes)
>        {
>            var query = _dbSet.AsQueryable();
>            includes.ToList().ForEach(x => query = query.Include(x));
>
>            return query;
>        }
>
>        public virtual PagedResult<T> GetPagedRequest(QueryRequest queryRequest)
>        {
>            var query = QueryHelper.GetFilteredQuery<T>(_dbSet.AsQueryable(), queryRequest);
>            var pagedResultMessage = QueryHelper.GetPagedResult(query, queryRequest);
>            return pagedResultMessage;
>        }
I don't know anything about your QueryRequest or QueryHelper classes, but if QueryRequest doesn't let you change the query, you may have problems with that class. I also don't understand why QueryHelper needs both an IQueryable and QueryRequest.

As for a generic class with a subset of data, that probably isn't going to work. The closest you are going to get with C# is either anonymous types, dynamic types, or datatables, and I don't think you are going to be able to pass in the necessary code to create those in as a list of strings or a dictionary. You could maybe pass in a Func that creates the objects, but you would be adding a lot of complexity to your code for probably very little gain.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform