0

So maybe someone can tell me what I am doing wrong here. I try to retrieve one row from a table that has only two columns in it, ID and HighestIDNumber. Each time I run the code, I get the "Invaild Column Name" error. I can not figure out why.

Public Shared Function NextEID() As String
    Using context As New iTracContext()
        Dim highestEid As highestEmployeeNumber
        highestEid = context.HighestEmpNumber.FirstOrDefault(Function(e) e.hightestIDnumber > 0)
    End Using
End Function

I have verified the column names are exactly the same everywhere it is used.

DreamTeK
  • 32,537
  • 27
  • 112
  • 171
wakgtech
  • 75
  • 6
  • 4
    `HighestIDNumber` is not the same as `hightestIDnumber`. – Andrew Morton Feb 03 '20 at 16:05
  • 1
    Right but how would that produce a run-time error? – djv Feb 03 '20 at 16:28
  • Understood, but I am only using hightestIDnumber. Which is what has me puzzled – wakgtech Feb 03 '20 at 16:28
  • @wakgtech So you're saying you have that typo in the table definition too? – GSerg Feb 03 '20 at 16:32
  • 2
    Your table name is HighestEmpNumber and your column name is hightestIDnumber (with a t). May be correct but unusual. Are you sure that's correct? However that's more likely to through a compiler error than runt time. So is it possible your EF model has not been updated and so doesn't match the SQL table and could be generating an SQL call with a column name the DB doesn't recognise? – Jon Roberts Feb 03 '20 at 16:34
  • @wakgtech Is [`Option Strict On`](https://stackoverflow.com/a/29985039/1115360)? – Andrew Morton Feb 03 '20 at 16:41
  • what about [Option Explicit Off](https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/option-explicit-statement)? (not sure it works with object properties or just variables) – djv Feb 03 '20 at 16:43
  • @djv None of those enable you to provide a non existing property name in a strongly typed lambda. For it to happen, `e` has to be `Object` in addition to `option strict off`. – GSerg Feb 03 '20 at 16:49
  • I think @JonRoberts is spot on and OP should update the model. [LINQ to SQL](https://stackoverflow.com/a/1110258/832052), [EF](https://stackoverflow.com/a/2959035/832052) – djv Feb 03 '20 at 16:57
  • Sorry for getting back so late to everyone. Andrew Morton, you are correct sir. That typo was the problem. 12 hour days looking at these 6 screens is getting to me! Thanks All! Andrew I would like to mark you answer as correct. – wakgtech Feb 04 '20 at 12:18

0 Answers0