Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Having trouble with my linq query in my model of MVC. I have an edmx which is composed of ObjectSet and EntityObject. this is where im getting the error "from c in CanaClie0012". when i go to definition it is going to my entityObject.

   public class ClientRepository
    {

        public List<ClientSearchResult> Search(ClientSearchFilter filter, string sortColumn, string sortOrder, int pageSize, int pageIndex, out int totalRecords)
        {

            var q = from c in CanaClie0012
                    select new ClientSearchResult
                    {
                        Client00130012 = c.Client00130012,
                        F1Pais00200012 = c.F1Pais00200012,
                        F1Cana02530012 = c.F1Cana02530012,
                        Direcc0012 = c.Direcc0012,
                    };

            if (!string.IsNullOrEmpty(filter.Client00130012))
            {
                q = q.Where(c => c.Client00130012.ToLower().Contains(filter.Client00130012.ToLower()));
            }
            if (!string.IsNullOrEmpty(filter.F1Pais00200012))
            {
                q = q.Where(c => c.F1Pais00200012.ToLower().Contains(filter.F1Pais00200012.ToLower()));
            }
            if (!string.IsNullOrEmpty(filter.F1Cana02530012))
            {
                q = q.Where(c => c.F1Cana02530012.ToLower().Contains(filter.F1Cana02530012.ToLower()));
            }
            if (!string.IsNullOrEmpty(filter.Direcc0012))
            {
                q = q.Where(c => c.F1Cana02530012.ToLower().Contains(filter.F1Cana02530012.ToLower()));
            }


            switch (sortColumn)
            {
                case "Client00130012":
                    q = (sortOrder == "desc") ? q.OrderByDescending(c => c.Client00130012) : q.OrderBy(c => c.Client00130012);
                    break;
                case "F1Pais00200012":
                    q = (sortOrder == "desc") ? q.OrderByDescending(c => c.F1Pais00200012) : q.OrderBy(c => c.F1Pais00200012);
                    break;
                case "Direcc0012":
                    q = (sortOrder == "desc") ? q.OrderByDescending(c => c.Direcc0012) : q.OrderBy(c => c.Direcc0012);
                    break;
                case "F1Cana02530012":
                    q = (sortOrder == "desc") ? q.OrderByDescending(c => c.F1Cana02530012) : q.OrderBy(c => c.F1Cana02530012);
                    break;
                default:
                    break;
            }
            totalRecords = q.Count();
            return q.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
        }


    }

I have already tried adding this:

List<CanaClie0012> clients = new List<CanaClie0012>();

But its returning null values. Kindly help me. Im lost here.

share|improve this question
    
What is CanaClie0012, what is the declaration of that identifier? –  Lasse V. Karlsen Jun 8 '13 at 18:29
    
CanaClie0012 wouldn't seem to be an Enumerable<T> or Queryable<T>. –  Joachim Isaksson Jun 8 '13 at 18:33
    
public partial class CanaClie0012 : EntityObject public ObjectSet<CanaClie0012> CanaClie0012 These are its declaration in the model.designer.cs –  rcadaoas Jun 8 '13 at 19:39
    
its name is also 'CanaClie0012'. should I change its name? @GertArnold –  rcadaoas Jun 8 '13 at 19:52
    
No, not necessarily (although it would help to tell them apart). But I would expect something like from c in context.CanaClie0012. Could you "zoom out" a bit an show the code around your query? (By editing your question). –  Gert Arnold Jun 8 '13 at 20:11

1 Answer 1

up vote 0 down vote accepted

Your right @Gert Arnold. that did solve my problem.. thank you.

  MMProdatEntities clients = new MMProdatEntities();

            public List<ClientSearchResult> Search(ClientSearchFilter filter, string sortColumn, string sortOrder, int pageSize, int pageIndex, out int totalRecords)
            {

                var q = from c in clients.CanaClie0012
                        join d in clients.Clientes0013 on c.Client00130012 equals d.Client0013 
                        select new ClientSearchResult
                        {
                            Client00130012 = c.Client00130012,
                            F1Pais00200012 = c.F1Pais00200012,
                            F1Cana02530012 = c.F1Cana02530012,
                            Direcc0012 = c.Direcc0012,
                        };

                if (!string.IsNullOrEmpty(filter.Client00130012))
                {
                    q = q.Where(c => c.Client00130012.ToLower().Contains(filter.Client00130012.ToLower()));
                }
                if (!string.IsNullOrEmpty(filter.F1Pais00200012))
                {
                    q = q.Where(c => c.F1Pais00200012.ToLower().Contains(filter.F1Pais00200012.ToLower()));
                }
                if (!string.IsNullOrEmpty(filter.F1Cana02530012))
                {
                    q = q.Where(c => c.F1Cana02530012.ToLower().Contains(filter.F1Cana02530012.ToLower()));
                }
                if (!string.IsNullOrEmpty(filter.Direcc0012))
                {
                    q = q.Where(c => c.Direcc0012.ToLower().Contains(filter.Direcc0012.ToLower()));
                }


                switch (sortColumn)
                {
                    case "Client00130012":
                        q = (sortOrder == "desc") ? q.OrderByDescending(c => c.Client00130012) : q.OrderBy(c => c.Client00130012);
                        break;
                    case "F1Pais00200012":
                        q = (sortOrder == "desc") ? q.OrderByDescending(c => c.F1Pais00200012) : q.OrderBy(c => c.F1Pais00200012);
                        break;
                    case "F1Cana02530012":
                        q = (sortOrder == "desc") ? q.OrderByDescending(c => c.F1Cana02530012) : q.OrderBy(c => c.F1Cana02530012);
                        break;
                    case "Direcc0012":
                        q = (sortOrder == "desc") ? q.OrderByDescending(c => c.Direcc0012) : q.OrderBy(c => c.Direcc0012);
                        break;
                    default:
                        q = (sortOrder == "desc") ? q.OrderByDescending(c => c.Client00130012) : q.OrderBy(c => c.Client00130012);
                        break;
                }
                totalRecords = q.Count();

                return q.Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.