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

  • Home
  • SEARCH
  • 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 665037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:39:58+00:00 2026-05-13T23:39:58+00:00

Why cant I do this: usuariosEntities usersDB = new usuariosEntities(); foreach (DataGridViewRow user in

  • 0

Why cant I do this:

usuariosEntities usersDB = new usuariosEntities();      
foreach (DataGridViewRow user in dgvUsuarios.Rows)
{
   var rowtoupdate = 
       usersDB.usuarios.Where(
       u => u.codigo_usuario == Convert.ToInt32(user.Cells[0].Value)
       ).First();
   rowtoupdate.password = user.Cells[3].Value.ToString();
}
usersDB.SaveChanges();

And have to do this:

usuariosEntities usersDB = new usuariosEntities();      
foreach (DataGridViewRow user in dgvUsuarios.Rows)
{
   int usercode = Convert.ToInt32(user.Cells[0].Value);
   var rowtoupdate = 
       usersDB.usuarios.Where(u => u.codigo_usuario == usercode).First();
   rowtoupdate.password = user.Cells[3].Value.ToString();
}
usersDB.SaveChanges();

I must admit it is a more readable code but why cant this be done?

  • 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-05-13T23:39:58+00:00Added an answer on May 13, 2026 at 11:39 pm

    The thing about it is that LINQ queries are transformed by the compiler into an expression tree. This expression tree is then converted into T-SQL and passed to the server. LINQ to SQL maps certain methods like String.Contains to the T-SQL equivalents.

    In the first example, LINQ apparently does not map Convert.ToInt32 to anything and the exception is thrown. The reason it works in your second example is because the Convert.ToInt32 call is done outside of the query so it isn’t part of the expression tree and doesn’t need to be converted to T-SQL.

    This MSDN page describes how LINQ to SQL translates various data types, operators, and methods into T-SQL. (Although the documentation does suggest Convert.ToInt32 is supported so I’m not sure what else might be going on here.)

    Sorry just realized this is ADO.NET Entity Framework, not LINQ to SQL. This page lists the ADO.NET Entity Framework mappings. It is a bit more restrictive, mostly because it needs to work with multiple providers.

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

Sidebar

Related Questions

I realize this perhaps a naive question but still I cant figure out how
I can't figure this out. Capistrano keeps giving me this error: ** [out ::
I'm thinking that the reason I can't do this is because it might be
Seems so basic, I can't believe I don't know this! I just need a
I can't quite figure this out. Microsoft Access 2000, on the report total section
Why can't you do this and is there are work around? You get this
I can't tell if this is a result of the jQuery I'm using, but
Here is an example that a forum poster gave, I can't tell if this
I get this error: Can't locate Foo.pm in @INC Is there an easier way
So this seems pretty basic but I can't get it to work. I have

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.