Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8222181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:11:26+00:00 2026-06-07T14:11:26+00:00

How can I solve this problem? Here is my code: DateTime dtInicio = new

  • 0

How can I solve this problem?

Here is my code:

    DateTime dtInicio = new DateTime();
    DateTime dtFim = new DateTime();
    Int32 codStatus = 0;

    if(!string.IsNullOrEmpty(collection["txtDtInicial"]))
        dtInicio = Convert.ToDateTime(collection["txtDtInicial"]);
    if(!string.IsNullOrEmpty(collection["txtDtFinal"]))
        dtFim = Convert.ToDateTime(collection["txtDtFinal"]);
    if (!string.IsNullOrEmpty(collection["StatusCliente"]))
        Convert.ToInt32(collection["StatusCliente"]);

    var listCLientResult = (from c in db.tbClientes
                           orderby c.id
                            where (c.effdt >= dtInicio || string.IsNullOrEmpty(collection["txtDtInicial"]) &&
                                 (c.effdt <= dtFim || string.IsNullOrEmpty(collection["txtDtFinal"])) &&
                                 (c.cod_status_viagem == codStatus || string.IsNullOrEmpty(collection["StatusCliente"])))
                                 select c);
    return View(listCLientResult);

The error I am getting is:

LINQ to Entities does not recognize the method ‘System.String get_Item (System.String)’, which can not be converted into an expression of the repository.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:11:27+00:00Added an answer on June 7, 2026 at 2:11 pm

    Linq queries performed against a database are translated to SQL before they can be executed; but collection["txtDtInicial"] can’t be translated to SQL, because there is no equivalent SQL syntax, and anyway the database doesn’t have access to collection. You need to extract collection["txtDtInicial"] to a variable first, and use only this variable in the query.

    Here’s what I would do:

    DateTime dtInicio = DateTime.MinValue;
    DateTime dtFim = DateTime.MaxValue;
    Int32 codStatus = 0;
    
    if(!string.IsNullOrEmpty(collection["txtDtInicial"]))
        dtInicio = Convert.ToDateTime(collection["txtDtInicial"]);
    if(!string.IsNullOrEmpty(collection["txtDtFinal"]))
        dtFim = Convert.ToDateTime(collection["txtDtFinal"]);
    if (!string.IsNullOrEmpty(collection["StatusCliente"]))
        codStatus = Convert.ToInt32(collection["StatusCliente"]);
    
    var listCLientResult = (from c in db.tbClientes
                           orderby c.id
                            where (c.effdt >= dtInicio) &&
                                 (c.effdt <= dtFim) &&
                                 (c.cod_status_viagem == codStatus)
                                 select c);
    return View(listCLientResult);
    

    By initializing dtInicio and dtFim to MinValue and MaxValue, you don’t need to check whether they are defined in the query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

just want to ask anyone here can solve this problem? I want to create
How can I solve this problem Cannot Create Forms. No MDI forms are currently
I can't solve this problem... I'm having some problems with fetched properties (not with
Can anybody help me to solve this problem. I am working on iphone development.
I've been trying to solve this problem for a while now and I can't
I've searched high and low in order to solve this problem, but I can't
I have worked on this problem for my entire day and can't solve it.
there's this interesting problem i can not solve myself. I will be very glad,
I have another problem that I can't solve I have a following code that
I'm pretty sure I can solve this problem with Java generics so I wanted

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.