Why do I get "Invalid Column Name" errors in EF4?

Posted by camainc on Stack Overflow See other posts from Stack Overflow or by camainc
Published on 2010-04-15T20:20:16Z Indexed on 2010/04/15 20:23 UTC
Read the original article Hit count: 1973

I am trying to learn Entity Framework 4.0.

Disclaimer 1: I am brand new to Entity Framework. I have successfully used LinqToSQL.

Disclaimer 2: I am really a VB.Net programmer, so the problem could be in the C# code.

Given this code snippet:

    public int Login(string UserName, string Password)
    {
       return _dbContext.Memberships
            .Where(membership => membership.UserName.ToLower() == UserName.ToLower() 
                && membership.Password == Password)
            .SingleOrDefault().PrimaryKey;
    }

Why do you suppose I get "Invalid column name" errors?

{"Invalid column name 'UserName'.\r\nInvalid column name 'Password'.\r\nInvalid column name 'UserName'.\r\nInvalid column name 'Password'."}

Those column names are spelled and cased correctly. I also checked the generated code for the entity in question, and those columns are properties in the entity. The intellisense and code completion also puts the column names into the expression just as they are here.

I am stumped by this. Any help would be much appreciated.

https://docs.google.com/leaf?id=0B-xLbzoqGvXvNjBmZmNjNDAtY2RhNC00NDA2LWIxNzMtYjhjNTYxMDIyZmZl&hl=en

© Stack Overflow or respective owner

Related posts about entity-framework

Related posts about linq-to-entities